package cn.piesat.scanning.business.xz.single;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.piesat.scanning.business.common.algorithm.processAlgorithm.SingleTaskAbstract;
import cn.piesat.scanning.business.xz.BuildAlgorithmFactory;
import cn.piesat.scanning.business.xz.service.BuildAlgorithmTaskService;
import cn.piesat.scanning.business.xz.vo.RuleVO;
import cn.piesat.scanning.dto.*;
import cn.piesat.scanning.service.*;
import cn.piesat.scanning.utils.DateUtils;
import cn.piesat.scanning.utils.FileUtil;
import cn.piesat.scanning.vo.TianQingParam;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.File;
import java.io.FilenameFilter;
import java.text.ParseException;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author xhl
 */
@Component
public class XzSingleTask extends SingleTaskAbstract {
    private Logger log = LoggerFactory.getLogger(XzSingleTask.class);

    @Value("${scanning.data.day}")
    private Integer nearDay;

    private final DateTimeFormatter TIME_FORMAT = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
    private final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("yyyyMMdd");
    private final DateTimeFormatter DATE_YEAR_FORMAT = DateTimeFormatter.ofPattern("yyyy");

    private static final String NULL = "NULL";
    /**
     * 同一谱段不同通道的时间差
     */
    private static final int DIFF_TIME_MINUTE = 3;

    private static final Logger logger = LoggerFactory.getLogger(XzSingleTask.class);

    @Autowired
    private HtScanningMetadataService htScanningMetadataService;
    @Autowired
    private DbDmsSchedulerTaskFileRecordService dbDmsSchedulerTaskFileRecordService;
    @Autowired
    private HtPathConfigurationService htPathConfigurationService;
    @Autowired
    private DbDmsScanningMetadataAuxInfoService dbDmsScanningMetadataAuxInfoService;
    @Autowired
    private DbDmsScanningValidationService dbDmsScanningValidationService;
    @Autowired
    private HtAlgorithmConfigurationService htAlgorithmConfigurationService;

    @Value("${spring.kafka.producer.interactiveExec.topic}")
    private String interactiveExecTopic;

    private Map<String, String> algorithmTaskServiceMap = new HashMap<>();
    @PostConstruct
    public void init() {
        algorithmTaskServiceMap.put("XIZANG_VEG","AlgorithmXIZANG_VEGServiceImpl");
    }

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    @Override
    public void parseRuleAndFindData(Map<String, Object> inputParams, Map<String, Object> ruleParams,
                                     Map<String, Integer> indexParams, HtScheduleJobDTO taskDTO) {

        if (inputParams.containsKey("bizId")) {
            //天擎
            String tianQingParam = assembleTianQingRule(inputParams, ruleParams, taskDTO);
            kafkaTemplate.send(interactiveExecTopic, tianQingParam);
        } else {
            //规则参数
            AlgorithmTaskRuleParam taskRuleParam = JSON.parseObject(JSON.toJSONString(ruleParams), AlgorithmTaskRuleParam.class);
            //路径参数
            AlgorithmTaskPathParam taskPathParam = JSON.parseObject(JSON.toJSONString(inputParams), AlgorithmTaskPathParam.class);
            //判断规则不为NULL但是输入路径为空的情况
            if (!rulePathExist(taskRuleParam, taskPathParam)) {
                return;
            }
            Boolean preProcess = false;

            JSON.parseObject(taskRuleParam.getPrimaryFile(), RuleVO.class);
            RuleVO primaryRuleVO = JSON.parseObject(taskRuleParam.getPrimaryFile(), RuleVO.class);
            //查找可执行的数据，默认查找配置文件中配置的时间文件，[状态为重做的文件]，记录表中不存在的主文件
            List<HtScanningMetadataDTO> execMetadataList = new ArrayList<>();
            HtAlgorithmConfigurationDTO algorithmDTO = htAlgorithmConfigurationService.findById(taskDTO.getAlgoId());
            //获取算法标识 SWAPDSTDET
            String adsType = algorithmDTO.getAlgorithmIdentify();
            execMetadataList.addAll(selectExecMainFileList(primaryRuleVO, preProcess, taskDTO, adsType, taskPathParam));
            execMetadataList.addAll(findRedoMetadataList(taskDTO.getId()));
            logger.info("集合数量:" + String.valueOf(execMetadataList.size()));
            assemble(taskRuleParam, taskPathParam, indexParams, execMetadataList, taskDTO);
        }
    }

    @Override
    public void parseRuleAndFindData(Map<String, Object> inputParams, Map<String, Object> ruleParams, HtScheduleJobDTO taskDTO) {

    }

    private void assemble(AlgorithmTaskRuleParam taskRuleParam, AlgorithmTaskPathParam taskPathParam, Map<String, Integer> indexParams,
                          List<HtScanningMetadataDTO> execMetadataList, HtScheduleJobDTO taskDTO) {
        //获取数据路径
        HtPathConfigurationDTO pathDTO = htPathConfigurationService.findById(taskDTO.getPathConfigId());
        Boolean preProcess = false;
        //获取算法信息 （算法名称，算法标识等）
        HtAlgorithmConfigurationDTO algorithmDTO = htAlgorithmConfigurationService.findById(taskDTO.getAlgoId());
        //获取算法标识 SWAPDSTDET
        String adsType = algorithmDTO.getAlgorithmIdentify();
        //后缀_TASK-ALL为多个主文件的情况
        if (adsType.endsWith("_TASK-ALL")) {
            Map<String, Object> execParams = new HashMap<>();
            //匹配primaryFile规则
            execParams.put("preprocess", preProcess);
            execParams.put("algorithmId", taskDTO.getAlgoId());
            execParams.put("pathConfigId", taskDTO.getPathConfigId());
            execParams.put("productDir", pathDTO.getOutputPath());
            execParams.put("productType", taskPathParam.getProductType());
            //组装算法参数
            Map<String, Object> algorithmParams = new HashMap<>();
            try {
                Map<Date, HtScanningMetadataDTO> collect = execMetadataList.stream()
                        .collect(Collectors.toMap(
                                x -> DateUtil.parse(x.getFileDate().substring(0,8), "yyyyMMdd"),
                                x -> x, (existing, replacement) -> existing
                        ));
                HtScanningMetadataDTO metadataDTO = null;
                for (Map.Entry<Date, HtScanningMetadataDTO> localDateListEntry : collect.entrySet()) {
                    metadataDTO = localDateListEntry.getValue();
                    algorithmParams = initAlgorithmTaskALL(adsType, metadataDTO, taskRuleParam, taskPathParam, indexParams, pathDTO.getScanningPath());
                    if ((algorithmParams.get("parameter01") != null)) {
                        log.info("数据存在");
                        updateRecordAndSendMessage(execParams, taskDTO, metadataDTO.getFileName(), metadataDTO.getFileDate(), algorithmParams);
                    } else {
                        log.info("数据不存在,已经跳过");
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            for (HtScanningMetadataDTO metadataDTO : execMetadataList) {
                Map<String, Object> execParams = new HashMap<>();
                //匹配primaryFile规则
                String primaryFile = pathDTO.getScanningPath() + File.separator + metadataDTO.getFilePath();
                execParams.put("preprocess", preProcess);
                execParams.put("algorithmId", taskDTO.getAlgoId());
                execParams.put("pathConfigId", taskDTO.getPathConfigId());
                execParams.put("fileDate", metadataDTO.getFileDate());
                execParams.put("lon", metadataDTO.getLon());
                execParams.put("lat", metadataDTO.getLat());
                execParams.put("taskPlanId", metadataDTO.getTaskPlanId());
                execParams.put("subPlanId", metadataDTO.getSubPlanId());
                execParams.put("viewNumber", metadataDTO.getViewNumber());
                execParams.put("productDir", pathDTO.getOutputPath());
                execParams.put("productType", taskPathParam.getProductType());
                //组装算法参数
                Map<String, Object> algorithmParams = new HashMap<>();
                try {
                    BuildAlgorithmFactory buildAlgorithmFactory = new BuildAlgorithmFactory();
//                    algorithmParams = initAlgorithmParams(adsType, primaryFile, metadataDTO.getFilePath(), taskRuleParam, taskPathParam, indexParams, metadataDTO.getFileDate(), pathDTO.getScanningPath());
                    Object buildParamsInstance = buildAlgorithmFactory.getBuildParamsInstance(adsType);
                    BuildAlgorithmTaskService buildAlgorithmTaskService=(BuildAlgorithmTaskService)buildParamsInstance;
                    algorithmParams =buildAlgorithmTaskService.initAlgorithmParams(adsType, primaryFile, metadataDTO.getFilePath(), taskRuleParam, taskPathParam,
                            indexParams, metadataDTO.getFileDate(), pathDTO.getScanningPath(), metadataDTO);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if ((algorithmParams.get("parameter01") != null)) {
                    log.info("数据存在");
                    updateRecordAndSendMessage(execParams, taskDTO, metadataDTO.getFileName(), metadataDTO.getFileDate(), algorithmParams);
                } else {
                        log.info("数据不存在,已经跳过");

                }
            }
        }

    }

    //
    private Map<String, Object> initAlgorithmTaskALL(String adsType, HtScanningMetadataDTO execMetadata, AlgorithmTaskRuleParam taskRuleParam,
                                                     AlgorithmTaskPathParam taskPathParam, Map<String, Integer> indexParams, String scanningPath) throws ParseException {
        Map<String, Object> algorithmParams = new HashMap<>();
        String filePath = execMetadata.getFilePath();
        String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
        String fileType = fileName.substring(fileName.lastIndexOf(".") + 1);
        if ("LAMR_WORD_TASK-ALL".equals(adsType)) {
//            List<String> collect = execMetadataList.stream().map(x -> taskPathParam.getParameter02() + File.separator + x.getFilePath()).collect(Collectors.toList());
//            String filePath = execMetadata.getFilePath();
//            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
//            String fileType = fileName.substring(fileName.lastIndexOf(".") + 1);
//            String[] split = fileName.split("_");
//            String prodcut = split[1];
//            String satellite = split[4];
//            String level = split[3];
//            String moduleIid = split[0];
//            String productMode = split[8];
//            String startTime = split[9];
//            Date start = DateUtil.parse(startTime, "yyyyMMddHHmmss");
//            Date lastYear = DateUtil.offsetMonth(start, -12);
//            String dataTimeStr = DateUtil.format(lastYear, "yyyyMMddHHmmss");
//            List<HtScanningMetadataDTO> lastYearList = htScanningMetadataService.selectByNotRegion
//                    (dataTimeStr, level, satellite, prodcut, productMode, moduleIid, fileType);
//            List<String> lastYearFileList = lastYearList.stream().map(x -> taskPathParam.getParameter02() + File.separator + x.getFilePath()).collect(Collectors.toList());
//            Map<String, Object> params = new HashMap<>();
//            params.put("primaryFile", collect);
//            params.put("lastYearFile", lastYearFileList);
//            params.put("auxPath", taskPathParam.getParameter03());
//            algorithmParams.put("parameter00", adsType);
//            algorithmParams.put("parameter01", params);
        }else if ("LAKE_ICE_DAY_TASK-ALL".equals(adsType)) {
            ///FY3D/MERSI/L1/1000M/2023/20230101/FY3D_MERSI_GBAL_L1A_GLL_20230101_0700_1000M.TIFF
            String[] split = fileName.split("_");
            //FY3D_MERSI_GBAL_L1A_GLL_20230101_0700_1000M.TIFF
            String region = split[2];
            String satellite = split[0];
            String level = split[3];
            String sensor = split[1];
            String time = split[5];
            String startTime =time+"000000";
            String endTime =time+"235959";

            List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findBySensor(startTime, endTime, level, satellite,
                    "FDI", region, fileType,sensor);
            List<String> collect1 = metadataDTOList.stream().map(x -> taskPathParam.getParameter02() + File.separator + x.getFilePath()).collect(Collectors.toList());
            DateTime endDateTime = DateUtil.parse(endTime, "yyyyMMddHHmmss");
            Date startDate = DateUtil.offsetMonth(endDateTime, -60).toJdkDate();
            String startDateStr = DateUtil.format(startDate, "yyyyMMddHHmmss");
            List<Object[]> regionAndFilePath = htScanningMetadataService.findRegionAndFilePath(startDateStr, endTime, taskPathParam.getParameter04(), taskPathParam.getParameter07(),
                    taskPathParam.getParameter05(), taskPathParam.getParameter08());
            if (regionAndFilePath.isEmpty()) {
                algorithmParams.put("parameter01", null);
            }

            List<String> stringList = new ArrayList<>();
            for (Object[] objects : regionAndFilePath) {
                stringList.add(taskPathParam.getParameter02()+objects[1]);
            }
            String join = StrUtil.join(",", collect1);
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", join);
            params.put("auxPath", taskPathParam.getParameter03());
            params.put("lakeRegion", stringList);
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        }else if ("LAKE_WATER_TASK-ALL".equals(adsType)){
            String[] s = fileName.split("_");
            Map<String, Object> params = new HashMap<>();
            if (taskPathParam.getParameter06().equals("1")) {

                String startTime = s[5] + "000000";
                String endTime = s[5] + "235959";
                //GF1_WFV1_GBAL_L1F_GLL_20230721_114307_16M_MSS.json
                List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findByMetadata(startTime, endTime, s[3], s[0],
                        s[3], s[2], "TIFF");
                List<String> collect = metadataDTOList.stream().map(x -> scanningPath + File.separator + x.getFilePath()).collect(Collectors.toList());
                String join = StrUtil.join(",", collect);
                params.put("primaryFile", join);
                params.put("auxPath", taskPathParam.getParameter02());
                params.put("primaryResult", "");
                params.put("clipRegion", taskPathParam.getParameter03());
                params.put("regionId", taskPathParam.getParameter04());
                params.put("regionName", taskPathParam.getParameter05());
                params.put("aloType", Integer.parseInt(taskPathParam.getParameter06()));
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            } else {
                //LKR_LADM_YZYC_L3_GF1_WFV1_0016M_GLL_MOAD_20230624000000_20230624235959.SHP
                String month = s[9].substring(4, 6); // 假设月份信息在日期字符串的第5位和第6位
                //3-4-5    6-7-8  9-10-11  12-1-2
                String quarter = null;
                switch (month) {
                    case "03":
                    case "04":
                    case "05":
                        quarter = "1";
                        break;
                    case "06":
                    case "07":
                    case "08":
                        quarter = "2";
                        break;
                    case "09":
                    case "10":
                    case "11":
                        quarter = "3";
                        break;
                    case "12":
                    case "01":
                    case "02":
                        quarter = "4";
                        break;
                }
                String year = s[9].substring(0, 4);
                String startTime = null, endTime = null;
                if ("1".equals(quarter)) {
                    startTime = year + "0301000000";
                    endTime = year + "0531235959";
                } else if ("2".equals(quarter)) {
                    startTime = year + "0601000000";
                    endTime = year + "0831235959";
                } else if ("3".equals(quarter)) {
                    startTime = year + "0901000000";
                    endTime = year + "1131235959";
                } else if ("4".equals(quarter)) {
                    startTime = year + "12000000";
                    int i = Integer.parseInt(year);
                    int nextYear = i + 1;
                    endTime = nextYear + "0231235959";
                }
                List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findOneByDate(startTime, endTime, s[3], s[4],
                        s[1], s[8], s[0], "SHP");
                Map<String, Optional<HtScanningMetadataDTO>> maxAreaByRegion = metadataDTOList.stream()
                        .collect(Collectors.groupingBy(HtScanningMetadataDTO::getRegion,
                                Collectors.maxBy(Comparator.comparing(HtScanningMetadataDTO::getArea))));

                // 根据 region 分组并找到每个组内 area 最大的对象，并获取其 filepath 字段
                Map<String, Optional<String>> maxAreaFilePathByRegion = metadataDTOList.stream()
                        .collect(Collectors.groupingBy(HtScanningMetadataDTO::getRegion,
                                Collectors.collectingAndThen(
                                        Collectors.maxBy(Comparator.comparing(HtScanningMetadataDTO::getArea)),
                                        dtoOpt -> dtoOpt.map(HtScanningMetadataDTO::getFilePath)
                                )));
                // 输出每个区域对应的最大 area 对象的 filepath
                List<String> filePathList = new ArrayList<>();
                for (Map.Entry<String, Optional<String>> entry : maxAreaFilePathByRegion.entrySet()) {
                    String region = entry.getKey();
                    Optional<String> filepathOpt = entry.getValue();
                    if (filepathOpt.isPresent()) {
                        String filepath = filepathOpt.get();
                        String primaryResult = scanningPath + File.separator + filepath;
                        filePathList.add(primaryResult);
                    }
                }
                String join = StrUtil.join(",", filePathList);
                HtScanningMetadataDTO maxAreaDTO = metadataDTOList.stream()
                        .max(Comparator.comparing(HtScanningMetadataDTO::getArea))
                        .orElse(null);
                if (null == maxAreaDTO) {
                    algorithmParams.put("parameter01", null);
                } else {
//                    String primaryResult = scanningPath + File.separator + maxAreaDTO.getFilePath();
//                    String maxAreaFilePath = filePath.substring(maxAreaDTO.getFilePath().lastIndexOf("/") + 1);
//                    String[] maxAreaSplit = maxAreaFilePath.split("_");
                    params.put("primaryFile", "");
                    params.put("auxPath", taskPathParam.getParameter02());
                    params.put("primaryResult", join);
                    params.put("clipRegion", taskPathParam.getParameter03());
//                    params.put("regionId", maxAreaSplit[2]);
                    params.put("regionId", "");
//                    params.put("regionName", taskPathParam.getParameter05());
                    params.put("regionName", "");
                    params.put("aloType", Integer.parseInt(taskPathParam.getParameter06()));
                    algorithmParams.put("parameter00", adsType);
                    algorithmParams.put("parameter01", params);
                }
            }
            return algorithmParams;
        }else if ("FY3D_MWRI_L1_10KM_TASK-ALL".equals(adsType)) {
            String[] split = fileName.split("_");
            //FY3D_MWRID_GBAL_L1_20231225_2014_010KM_MS.HDF
            String region = split[2];
            String satellite = split[0];
            String level = split[3];
            String sensor = split[1];
            String time = split[4];
            String startTime =time+"000000";
            String endTime =time+"235959";

            List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findBySensor(startTime, endTime, level, satellite,
                    "FY3D_MWRI", region, "HDF",sensor);

            List<String> collect1 = metadataDTOList.stream().map(x -> taskPathParam.getParameter02() + File.separator + x.getFilePath()).collect(Collectors.toList());

            String join = StrUtil.join(",", collect1);
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", join);
            params.put("SSLRID", taskPathParam.getParameter04());
            params.put("WorkFlow", taskPathParam.getParameter03());
            params.put("Thumbnail", false);
            params.put("ExportDEM", false);
            params.put("ExportAngles", false);
            params.put("SingleBand", false);
            params.put("ExportIMG", true);
            params.put("Projection", true);
            params.put("ProjectionIdentify", "GLL");
            params.put("Region", taskPathParam.getParameter06());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        }

        return algorithmParams;
    }

    private Map<String, Object> initAlgorithmParams(String adsType, String primaryFile, String filePath, AlgorithmTaskRuleParam taskRuleParam,
                                                    AlgorithmTaskPathParam taskPathParam, Map<String, Integer> indexParams, String fileDate, String scanningPath) throws ParseException {
        primaryFile = FilenameUtils.separatorsToUnix(primaryFile);
        Map<String, Object> algorithmParams = new HashMap<>();
        algorithmParams.put("parameter00", primaryFile);
        if ("XIZANG_VEG".equals(adsType)) {
            //基础植被指数算法get()
            ///FY3D_MERSI_GBAL_L1A_GLL_20230701_0905_1000M.nc
            //LAD8_OLITIRS_GBAL_L1F_GLL_20230822_051039_0030M.TIFF
            //S2B_MSI_T45RWL_L1F_GLL_20230718_043709_0020M.TIFF
            //FY4A_AGRI_DISK_1047E_L1B_FDI_GLL_20230731084500_20230731085959_4000M.NC
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String fileType = fileName.substring(fileName.lastIndexOf(".") + 1);
            String[] s1 = fileName.split("_");
            String startDate;
            String parameter07 = taskPathParam.getParameter07();
            if ("FY4A".equals(parameter07)) {
                startDate = s1[7];
            } else if ("LAD8".equals(parameter07) || "S2B".equals(parameter07) || "LAD9".equals(parameter07)) {
                startDate = s1[5] + s1[6];
            } else {
                startDate = s1[5] + s1[6] + "00";
            }
            HtScanningMetadataDTO metadataDTO;
            if ("S2B".equals(taskPathParam.getParameter07())) {
                metadataDTO = htScanningMetadataService.findMetaDataDto(startDate, taskPathParam.getParameter04(), taskPathParam.getParameter07(),
                        taskPathParam.getParameter05(), s1[2], fileType, "BAS");
            } else {
                metadataDTO = htScanningMetadataService.findMetaDataDto(startDate, taskPathParam.getParameter04(), taskPathParam.getParameter07(),
                        taskPathParam.getParameter05(), taskPathParam.getParameter06(), fileType, "BAS");
            }
            if (null == metadataDTO) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("L2File", taskPathParam.getParameter02() + metadataDTO.getFilePath());
                params.put("auxPath", taskPathParam.getParameter03());
                params.put("satID", parameter07);
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("EVCI".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] s = fileName.split("_");
            String year = s[9].substring(0, 4);
            String moduleIid = s[0];
            String productMode = s[8];
            String startTime = year + "0501000000";
            String endTime = year + "0930000000";
            List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findOneByDate(startTime, endTime, taskPathParam.getParameter04(), taskPathParam.getParameter07(),
                    taskPathParam.getParameter05(), taskPathParam.getParameter06(), productMode, moduleIid, taskPathParam.getParameter08());
            List<String> collect = metadataDTOList.stream().map(x -> taskPathParam.getParameter02() + File.separator + x.getFilePath()).collect(Collectors.toList());
            String join = StrUtil.join(",", collect);
            params.put("primaryFile", join);
            params.put("satelliteName", taskPathParam.getParameter07());
            params.put("L2file", "");
            params.put("auxPath", taskPathParam.getParameter03());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("WNDI".equals(adsType) || "WCI".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            params.put("satelliteName", taskPathParam.getParameter07());
            params.put("auxPath", taskPathParam.getParameter03());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("HI".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            params.put("L2file", "");
            params.put("auxPath", taskPathParam.getParameter03());
            params.put("satelliteName", taskPathParam.getParameter07());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("GI".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] s1 = fileName.split("_");
            String startDate = s1[9];
            HtScanningMetadataDTO metadataDTO = htScanningMetadataService.findMetaDataDto(startDate, taskPathParam.getParameter04(), taskPathParam.getParameter07(),
                    taskPathParam.getParameter05(), taskPathParam.getParameter06(), "NC", "BAS");
            if (null == metadataDTO) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("L2file", taskPathParam.getParameter02() + metadataDTO.getFilePath());
                params.put("auxPath", taskPathParam.getParameter03());
                params.put("satelliteName", taskPathParam.getParameter07());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("DI".equals(adsType) || "WI".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] s1 = fileName.split("_");
            String startDate;
            String parameter07 = taskPathParam.getParameter07();
            if ("FY4A".equals(parameter07)) {
                startDate = s1[7];
            } else if ("LAD8".equals(parameter07) || "S2B".equals(parameter07) || "LAD9".equals(parameter07)) {
                startDate = s1[5] + s1[6];
            } else {
                startDate = s1[5] + s1[6] + "00";
            }
            HtScanningMetadataDTO metadataDTO = null;
            if ("S2B".equals(taskPathParam.getParameter07())) {
                metadataDTO = htScanningMetadataService.findMetaDataDto(startDate, taskPathParam.getParameter04(), taskPathParam.getParameter07(),
                        taskPathParam.getParameter05(), s1[2], "TIFF", "BAS");
            } else {
                metadataDTO = htScanningMetadataService.findMetaDataDto(startDate, taskPathParam.getParameter04(), taskPathParam.getParameter07(),
                        taskPathParam.getParameter05(), taskPathParam.getParameter06(), "TIFF", "BAS");
            }
            if (null == metadataDTO) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("L2file", taskPathParam.getParameter02() + metadataDTO.getFilePath());
                params.put("auxPath", taskPathParam.getParameter03());
                params.put("satelliteName", taskPathParam.getParameter07());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("XIZANG_GSE_GPP".equals(adsType)
                || "XIZANG_FOR_GPP".equals(adsType)
                || "XIZANG_GSE_NPP".equals(adsType)
                || "XIZANG_FOR_NPP".equals(adsType)
                || "XIZANG_GSE_NEP".equals(adsType)
                || "XIZANG_FOR_NEP".equals(adsType)
        ) {
            //草地碳汇与森林碳汇  森林地上生物量AGB算法(XIZANG_FOR_AGB)
            ///1000M/2022/20220730/FY3D_MERSI_GBAL_L1B_GLL_20220730_0700_1000M.NC
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] s1 = fileName.split("_");
            String startDate;
            String parameter07 = taskPathParam.getParameter07();
            if ("FY4A".equals(parameter07)) {
                startDate = s1[7];
            } else if ("LAD8".equals(parameter07) || "S2B".equals(parameter07) || "LAD9".equals(parameter07)) {
                startDate = s1[5] + s1[6];
            } else {
                startDate = s1[5] + s1[6] + "00";
            }
            HtScanningMetadataDTO metadataDTO = null;
            if ("S2B".equals(taskPathParam.getParameter07())) {
                metadataDTO = htScanningMetadataService.findMetaDataDto(startDate, taskPathParam.getParameter04(), taskPathParam.getParameter07(),
                        taskPathParam.getParameter05(), s1[2], "TIFF", "BAS");
            } else {
                metadataDTO = htScanningMetadataService.findMetaDataDto(startDate, taskPathParam.getParameter04(), taskPathParam.getParameter07(),
                        taskPathParam.getParameter05(), taskPathParam.getParameter06(), "TIFF", "BAS");
            }
            if (null == metadataDTO) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("l2File", taskPathParam.getParameter02() + metadataDTO.getFilePath());
                params.put("auxPath", taskPathParam.getParameter03());
                params.put("era5Path", "/mnt/sfs/auxdata/parm_forest/ERA5/");
                params.put("satelliteName", taskPathParam.getParameter07());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("XIZANG_FOR_AGB".equals(adsType)) {
            //森林地上生物量AGB算法(XIZANG_FOR_AGB)
            ///1000M/2022/20220730/FY3D_MERSI_GBAL_L1B_GLL_20220730_0700_1000M.NC
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] s1 = fileName.split("_");
            String startDate;
            String parameter07 = taskPathParam.getParameter07();
            if ("FY4A".equals(parameter07)) {
                startDate = s1[7];
            } else if ("LAD8".equals(parameter07) || "S2B".equals(parameter07) || "LAD9".equals(parameter07)) {
                startDate = s1[5] + s1[6];
            } else {
                startDate = s1[5] + s1[6] + "00";
            }
            HtScanningMetadataDTO metadataDTO = htScanningMetadataService.findMetaDataDto(startDate, taskPathParam.getParameter04(), taskPathParam.getParameter07(),
                    taskPathParam.getParameter05(), taskPathParam.getParameter06(), "TIFF", "BAS");
            HtScanningMetadataDTO l2LaiDto = htScanningMetadataService.findMetaDataDto(startDate, taskPathParam.getParameter04(), taskPathParam.getParameter07(),
                    "LAI", taskPathParam.getParameter06(), "TIFF", "BAS");
            if (null == metadataDTO || null == l2LaiDto) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("l2File", taskPathParam.getParameter02() + metadataDTO.getFilePath());
                params.put("auxPath", taskPathParam.getParameter03());
                params.put("l2LaiFile", taskPathParam.getParameter02() + l2LaiDto.getFilePath());
                params.put("era5Path", "/mnt/sfs/auxdata/parm_forest/ERA5/");
                params.put("satelliteName", taskPathParam.getParameter07());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("XIZANG_FOR_FSV".equals(adsType)) {
            //森林蓄积量FSV算法
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            params.put("auxPath", taskPathParam.getParameter03());
            params.put("satelliteName", taskPathParam.getParameter07());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);

        } else if ("XIZANG_DRT01".equals(adsType)) {
            //干旱指数同期对比
            //DRT_VSWI_540000_L3_FY3D_MERSI_1000M_GLL_MOTD_20230711000000_20230720000000.TIFF
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] split = fileName.split("_");
            //String productMode = split[8];
            String prodcut = split[1];
            String region = split[2];
            String level = split[3];
            String moduleIid = split[0];
            String productMode = split[8];
            String startTime = split[9];
            Date start = DateUtil.parse(startTime, "yyyyMMddHHmmss");
            Date lastYear = DateUtil.offsetMonth(start, -12);
            String startTimeStr = DateUtil.format(lastYear, "yyyyMMddHHmmss");
            HtScanningMetadataDTO metadataDTO = htScanningMetadataService.findMetadataByParam(startTimeStr, level, taskPathParam.getParameter03(),
                    prodcut.replace("-", ""), region, productMode, moduleIid, taskPathParam.getParameter08());
            if (null == metadataDTO) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("L3File", taskPathParam.getParameter04() + metadataDTO.getFilePath());
                params.put("auxPath", taskPathParam.getParameter02());
                params.put("satID", taskPathParam.getParameter03());
                params.put("productName", taskPathParam.getParameter05());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("XIZANG_CLM".equals(adsType)) {
            //卫星云检测产品反演 CLM
            if ("FY4A".equals(taskPathParam.getParameter03())) {
                // FY4A_AGRI_DISK_1047E_L1B_FDI_GLL_20230701040000_20230701041459_4000M.NC
                String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
                String fileType = fileName.substring(fileName.lastIndexOf(".") + 1);
                String[] s1 = fileName.split("_");
                Date endTime = DateUtil.parse(s1[7], "yyyyMMddHHmmss");
                List<String> listDate = new ArrayList<>();
                for (int i = 1; i <= 10; i++) {
                    Date startTime = DateUtil.offsetDay(endTime, -i);
                    String startTimeStr = DateUtil.format(startTime, "yyyyMMddHHmmss");
                    listDate.add(startTimeStr);
                }
                List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findByMetadata(listDate, s1[4],
                        taskPathParam.getParameter03(), s1[5], s1[2], fileType).stream().sorted(Comparator.comparing(HtScanningMetadataDTO::getFileDate)).collect(Collectors.toList());
                List<String> filePathList = metadataDTOList.stream().map(x -> scanningPath + x.getFilePath()).collect(Collectors.toList());
                Map<String, Object> params = new HashMap<>();
                params.put("primaryFile", filePathList);
                params.put("auxPath", taskPathParam.getParameter02());
                params.put("satelliteName", taskPathParam.getParameter03());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            } else {
                //FY3D_MERSI_GBAL_L1A_GLL_20230731_0820_1000M.NC
                //AQUA_MODIS_GBAL_L1B_GLL_20230708_0627_1000M.NC
                //TERRA_MODIS_GBAL_L1B_GLL_20230731_1450_1000M.NC
                Map<String, Object> params = new HashMap<>();
                params.put("primaryFile", primaryFile);
                params.put("auxPath", taskPathParam.getParameter02());
                params.put("satelliteName", taskPathParam.getParameter03());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("Tibet_Grass_RPP".equals(adsType)) {
            //草地FY3D_GPP对NDVI相关性分析
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] split = fileName.split("_");
            String region = split[2];
            String level = split[3];
            String satellite = split[4];
            String moduleIid = split[0];
            String productMode = split[8];
            String startTime = split[9];
            HtScanningMetadataDTO metadataDTO = htScanningMetadataService.findMetadataByParam(startTime, level, satellite,
                    taskPathParam.getParameter05().replace("-", ""), region, productMode.replace("PO", "MO"), moduleIid, "TIFF");
            if (null == metadataDTO) {
                algorithmParams.put("parameter01", null);
            } else {
                Map<String, Object> params = new HashMap<>();
                params.put("primaryFile", primaryFile);
                params.put("relFile", taskPathParam.getParameter02() + metadataDTO.getFilePath());
                params.put("auxPath", taskPathParam.getParameter03());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("XIZANG_FOR_PP".equals(adsType)) {
            //森林FY3D_GPP对NDVI相关性分析
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] split = fileName.split("_");
            String region = split[2];
            String level = split[3];
            String satellite = split[4];
            String moduleIid = split[0];
            String productMode = split[8];
            String startTime = split[9];
            HtScanningMetadataDTO metadataDTO = htScanningMetadataService.findMetadataByParam(startTime, level, satellite,
                    taskPathParam.getParameter05().replace("-", ""), region, productMode.replace("PO", "MO"), "BAS", "TIFF");
            if (null == metadataDTO) {
                algorithmParams.put("parameter01", null);
            } else {
                Map<String, Object> params = new HashMap<>();
                params.put("primaryFile", primaryFile);
                params.put("relFile", taskPathParam.getParameter02() + metadataDTO.getFilePath());
                params.put("satelliteName", satellite);
                params.put("auxPath", taskPathParam.getParameter03());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("LAKE_WATER".equals(adsType)) {
            //日尺度湖泊水体面积提取算法
            //1为日尺度,2为季尺度
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] s = fileName.split("_");
            Map<String, Object> params = new HashMap<>();
            if (taskPathParam.getParameter06().equals("1")) {

                String startTime = s[5] + "000000";
                String endTime = s[5] + "235959";
                //GF1_WFV1_GBAL_L1F_GLL_20230721_114307_16M_MSS.json
                List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findByMetadata(startTime, endTime, s[3], s[0],
                        s[3], s[2], "TIFF");
                List<String> collect = metadataDTOList.stream().map(x -> scanningPath + File.separator + x.getFilePath()).collect(Collectors.toList());
                String join = StrUtil.join(",", collect);
                params.put("primaryFile", join);
                params.put("auxPath", taskPathParam.getParameter02());
                params.put("primaryResult", "");
                params.put("clipRegion", taskPathParam.getParameter03());
                params.put("regionId", taskPathParam.getParameter04());
                params.put("regionName", taskPathParam.getParameter05());
                params.put("aloType", Integer.parseInt(taskPathParam.getParameter06()));
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            } else {
                //LKR_LADM_YZYC_L3_GF1_WFV1_0016M_GLL_MOAD_20230624000000_20230624235959.SHP
                String month = s[9].substring(4, 6); // 假设月份信息在日期字符串的第5位和第6位
                //3-4-5    6-7-8  9-10-11  12-1-2
                String quarter = null;
                switch (month) {
                    case "03":
                    case "04":
                    case "05":
                        quarter = "1";
                        break;
                    case "06":
                    case "07":
                    case "08":
                        quarter = "2";
                        break;
                    case "09":
                    case "10":
                    case "11":
                        quarter = "3";
                        break;
                    case "12":
                    case "01":
                    case "02":
                        quarter = "4";
                        break;
                }
                String year = s[9].substring(0, 4);
                String startTime = null, endTime = null;
                if ("1".equals(quarter)) {
                    startTime = year + "0301000000";
                    endTime = year + "0531235959";
                } else if ("2".equals(quarter)) {
                    startTime = year + "0601000000";
                    endTime = year + "0831235959";
                } else if ("3".equals(quarter)) {
                    startTime = year + "0901000000";
                    endTime = year + "1131235959";
                } else if ("4".equals(quarter)) {
                    startTime = year + "12000000";
                    int i = Integer.parseInt(year);
                    int nextYear = i + 1;
                    endTime = nextYear + "0231235959";
                }
                List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findOneByDate(startTime, endTime, s[3], s[4],
                        s[1], s[2], s[8], s[0], "SHP");
                HtScanningMetadataDTO maxAreaDTO = metadataDTOList.stream()
                        .max(Comparator.comparing(HtScanningMetadataDTO::getArea))
                        .orElse(null);
                if (null == maxAreaDTO) {
                    algorithmParams.put("parameter01", null);
                } else {
                    String primaryResult = scanningPath + File.separator + maxAreaDTO.getFilePath();
                    String maxAreaFilePath = filePath.substring(maxAreaDTO.getFilePath().lastIndexOf("/") + 1);
                    String[] maxAreaSplit = maxAreaFilePath.split("_");
                    params.put("primaryFile", "");
                    params.put("auxPath", taskPathParam.getParameter02());
                    params.put("primaryResult", primaryResult);
                    params.put("clipRegion", taskPathParam.getParameter03());
                    params.put("regionId", maxAreaSplit[2]);
                    params.put("regionName", taskPathParam.getParameter05());
                    params.put("aloType", Integer.parseInt(taskPathParam.getParameter06()));
                    algorithmParams.put("parameter00", adsType);
                    algorithmParams.put("parameter01", params);
                }
            }
        } else if ("XIZANG_LST".equals(adsType)) {
            //卫星陆表温度产品反演 LST
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            HtScanningMetadataDTO metadataDTO = htScanningMetadataService.findMetaDataDto(fileDate, taskPathParam.getParameter04(), taskPathParam.getParameter07(),
                    taskPathParam.getParameter05(), taskPathParam.getParameter06(), taskPathParam.getParameter08(), taskPathParam.getParameter09());
            if (null == metadataDTO) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("auxPath", taskPathParam.getParameter03());
                params.put("satelliteName", taskPathParam.getParameter07());
                params.put("L2file", taskPathParam.getParameter02() + metadataDTO.getFilePath());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("WATER_CHANGE".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            params.put("backgroundImg", "/mnt/sfs/tmp/wdq/output/GF1/WFV1/L3/LMCI/MOAY/16M/2023/20230711/LKR_LMCI_ZRMN_L3_GF1_WFV1_16M_GLL_MOAY_20230711123709_20230711123709.TIFF");
            params.put("auxPath", taskPathParam.getParameter03());
            params.put("regionId", "ZRNM");
            params.put("regionName", "");
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("FY3D_MERSI_L3_1000M".equals(adsType)) {
            //FY3D_L3级合成算法
            //GSE_NPP-_GBAL_L2_FY3D_MERSI_1000M_GLL_HHMM_20230731081500_20230731081500.TIFF
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String fileType = fileName.substring(fileName.lastIndexOf(".") + 1);
            String[] s = fileName.split("_");
            Map<String, Object> params = new HashMap<>();
            if (taskPathParam.getParameter05().contains("AD")) {
                String date = s[9].substring(0, 8);
                String startTime = date + "000000";
                String endTime = date + "235959";
                List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findOneByDate(startTime, endTime, s[3], s[4],
                        s[1].replace("-", ""), s[2], s[8], s[0], "TIFF");
                List<String> collect = metadataDTOList.stream().map(x -> scanningPath + File.separator + x.getFilePath()).collect(Collectors.toList());
                String join = StrUtil.join(",", collect);
                params.put("primaryFile", join);
                params.put("CompositeType", taskPathParam.getParameter02());
                params.put("SpecialTopic", taskPathParam.getParameter03());
                params.put("SSLRID", taskPathParam.getParameter04());
                params.put("Code", taskPathParam.getParameter08());
                params.put("RegionId", taskPathParam.getParameter06());
                params.put("Period", taskPathParam.getParameter05());
                params.put("ShpFile", "/mnt/sfs/resource/shp/xizang_sheng_polygon.shp");
                params.put("XmlFile", null);
                params.put("Scale", null);
//                params.put("ExportPng", Boolean.parseBoolean(taskPathParam.getParameter11()));
                params.put("ExportPng", true);
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            } else if (taskPathParam.getParameter05().contains("TD")) {
                //BAS_NDVI_540000_L3_FY3D_MERSI_1000M_GLL_MOAD_20230701000000_20230701235959.TIFF
                String startTime = s[9];
                if ("10".equals(startTime.substring(6, 8))) {
                    startTime = startTime.substring(0, 6) + "01" + startTime.substring(8);
                } else if ("20".equals(startTime.substring(6, 8))) {
                    startTime = startTime.substring(0, 6) + "11" + startTime.substring(8);
                } else if (Integer.parseInt(startTime.substring(6, 8)) >= 28) {
                    startTime = startTime.substring(0, 6) + "21" + startTime.substring(8);
                }
                String endTime = s[10].replace(".TIFF", "");
                List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findOneByDate(startTime, endTime, s[3], s[4],
                        taskPathParam.getParameter08(), taskPathParam.getParameter06(), s[8], taskPathParam.getParameter03(), "TIFF");
                List<String> collect = metadataDTOList.stream().map(x -> scanningPath + File.separator + x.getFilePath()).collect(Collectors.toList());
                String join = StrUtil.join(",", collect);
                params.put("primaryFile", join);
                params.put("CompositeType", taskPathParam.getParameter02());
                params.put("SpecialTopic", taskPathParam.getParameter03());
                params.put("SSLRID", taskPathParam.getParameter04());
                params.put("Code", taskPathParam.getParameter08());
                params.put("RegionId", taskPathParam.getParameter06());
                params.put("Period", taskPathParam.getParameter05());
                params.put("XmlFile", null);
                params.put("Scale", null);
//                params.put("ExportPng", Boolean.parseBoolean(taskPathParam.getParameter11()));
                params.put("ExportPng", true);
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            } else if (taskPathParam.getParameter05().contains("AM")) {
                //BAS_NDVI_540000_L3_FY3D_MERSI_1000M_GLL_MOAD_20230701000000_20230701235959.TIFF
                String productId = taskPathParam.getParameter08();
                String date = s[9].substring(0, 6);
                String startTime = date + "01000000";
                String endTime = date + "31235959";
                List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findOneByDate(startTime, endTime, s[3], s[4],
                        taskPathParam.getParameter08(), taskPathParam.getParameter06(), s[8], taskPathParam.getParameter03(), "TIFF");
                List<String> collect = metadataDTOList.stream().map(x -> scanningPath + File.separator + x.getFilePath()).collect(Collectors.toList());
                String join = StrUtil.join(",", collect);
                params.put("primaryFile", join);
                params.put("CompositeType", taskPathParam.getParameter02());
                params.put("SpecialTopic", taskPathParam.getParameter03());
                params.put("SSLRID", taskPathParam.getParameter04());
                params.put("Code", productId);
                params.put("RegionId", taskPathParam.getParameter06());
                params.put("Period", taskPathParam.getParameter05());
                params.put("XmlFile", null);
//                params.put("ExportPng", Boolean.parseBoolean(taskPathParam.getParameter11()));
                params.put("ExportPng", true);
                if ("GPP".equals(productId) || "NPP".equals(productId) || "NEP".equals(productId)) {
                    int day = DateUtils.dayByMonth(DateUtils.parseStrToDate(s[9], "yyyyMMddHHmmss"));
                    params.put("Scale", day);
                } else {
                    params.put("Scale", null);
                }
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            } else if (taskPathParam.getParameter05().contains("AQ")) {
                String month = s[9].substring(4, 6); // 假设月份信息在日期字符串的第5位和第6位
                String quarter = null;
                switch (month) {
                    case "03":
                    case "04":
                    case "05":
                        quarter = "1";
                        break;
                    case "06":
                    case "07":
                    case "08":
                        quarter = "2";
                        break;
                    case "09":
                    case "10":
                    case "11":
                        quarter = "3";
                        break;
                    case "12":
                    case "01":
                    case "02":
                        quarter = "4";
                        break;
                }
                String year = s[9].substring(0, 4);
                String startTime = null, endTime = null;
                if ("1".equals(quarter)) {
                    startTime = year + "0301000000";
                    endTime = year + "0531235959";
                } else if ("2".equals(quarter)) {
                    startTime = year + "0601000000";
                    endTime = year + "0831235959";
                } else if ("3".equals(quarter)) {
                    startTime = year + "0901000000";
                    endTime = year + "1131235959";
                } else if ("4".equals(quarter)) {
                    startTime = year + "12000000";
                    int i = Integer.parseInt(year);
                    int nextYear = i + 1;
                    endTime = nextYear + "0231235959";
                }
                List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findOneByDate(startTime, endTime, s[3], s[4],
                        taskPathParam.getParameter08(), taskPathParam.getParameter06(), s[8], taskPathParam.getParameter03(), "TIFF");
                List<String> collect = metadataDTOList.stream().map(x -> scanningPath + File.separator + x.getFilePath()).collect(Collectors.toList());
                if (metadataDTOList.size() == 0) {
                    algorithmParams.put("parameter01", null);
                } else {
                    String join = StrUtil.join(",", collect);
                    params.put("primaryFile", join);
                    params.put("CompositeType", taskPathParam.getParameter02());
                    params.put("SpecialTopic", taskPathParam.getParameter03());
                    params.put("SSLRID", taskPathParam.getParameter04());
                    params.put("Code", taskPathParam.getParameter08());
                    params.put("RegionId", taskPathParam.getParameter06());
                    params.put("Period", taskPathParam.getParameter05());
//                    params.put("ExportPng", Boolean.parseBoolean(taskPathParam.getParameter11()));
                    params.put("ExportPng", true);
                    params.put("Scale", taskPathParam.getParameter09());
                    algorithmParams.put("parameter00", adsType);
                    algorithmParams.put("parameter01", params);
                }
            } else if (taskPathParam.getParameter05().contains("AY")) {
                //BAS_NDVI_540000_L3_FY3D_MERSI_1000M_GLL_MOAD_20230701000000_20230701235959.TIFF
                String date = s[9].substring(0, 4);
                String startTime = date + "0101000000";
                String endTime = date + "1231235959";
                List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findOneByDate(startTime, endTime, s[3], s[4],
                        taskPathParam.getParameter08(), taskPathParam.getParameter06(), s[8], taskPathParam.getParameter03(), "TIFF");
                List<String> collect = metadataDTOList.stream().map(x -> scanningPath + File.separator + x.getFilePath()).collect(Collectors.toList());
                if (metadataDTOList.size() == 0) {
                    algorithmParams.put("parameter01", null);
                } else {
                    String join = StrUtil.join(",", collect);
                    params.put("primaryFile", join);
                    params.put("CompositeType", taskPathParam.getParameter02());
                    params.put("SpecialTopic", taskPathParam.getParameter03());
                    params.put("SSLRID", taskPathParam.getParameter04());
                    params.put("Code", taskPathParam.getParameter08());
                    params.put("RegionId", taskPathParam.getParameter06());
                    params.put("Period", taskPathParam.getParameter05());
//                    params.put("ExportPng", Boolean.parseBoolean(taskPathParam.getParameter11()));
                    params.put("ExportPng", true);
                    params.put("Scale", taskPathParam.getParameter09());
                    algorithmParams.put("parameter00", adsType);
                    algorithmParams.put("parameter01", params);
                }

            }
        } else if ("TVDI".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();

            //BAS_NDVI_GBAL_L3_FY3D_MERSI_1000M_GLL_MOAM_20230701055000_20230731082000.TIFF
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] s1 = fileName.split("_");
            String moduleIid = s1[0];
            String productMode = s1[8];
            String startTime = s1[9];
            HtScanningMetadataDTO metadataDTO = htScanningMetadataService.findMeatedataByMoudel(startTime, taskPathParam.getParameter04(), taskPathParam.getParameter07(),
                    taskPathParam.getParameter05(), taskPathParam.getParameter06(), productMode.replace("MO", "AO"), moduleIid, taskPathParam.getParameter08());
            if (null == metadataDTO) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("ndviFile", primaryFile);
                params.put("lstFile", taskPathParam.getParameter02() + File.separator + metadataDTO.getFilePath());
                double[] data = {78.4342298088595, 36.469084973447, 99.1142293466255, 26.8490851884708};
                params.put("area", data);
                params.put("tempPath", "/mnt/sfs/tmp/att/temp");
                params.put("method", taskPathParam.getParameter01());
                params.put("staticPath", taskPathParam.getParameter03());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("ImageRectify".equals(adsType)) {
            //L1E,L1F几何精校正
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] s = fileName.split("_");
            Map<String, Object> params = new HashMap<>();
            HtScanningMetadataDTO metadataDTO = htScanningMetadataService.findGF1(fileDate, s[1], "L1", s[0],
                    s[0], "GBAL", "xml");
            if (null == metadataDTO) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("primaryFile", primaryFile);
                params.put("geofile", taskPathParam.getParameter01() + metadataDTO.getFilePath());
                params.put("SSLRID", taskPathParam.getParameter02());
                params.put("WorkFlow", taskPathParam.getParameter03());
                params.put("Format", taskPathParam.getParameter09());
                params.put("ExportIMG", true);
                params.put("Region", taskPathParam.getParameter05());
                params.put("Bands", taskPathParam.getParameter04());
                params.put("ProjectionIdentify", "GLL");
                params.put("ExportAngles", false);
                boolean b = Boolean.parseBoolean(taskPathParam.getParameter06());
                params.put("IsOrtho", b);
                params.put("ExportDEM", Boolean.parseBoolean(taskPathParam.getParameter07()));
                params.put("Projection", Boolean.parseBoolean(taskPathParam.getParameter08()));
                params.put("Thumbnail", false);
                params.put("SingleBand", false);
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("GF_L1".equals(adsType)) {
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            //GF2_PMS2_E91.6_N29.0_20220725_L1A0006623933-PAN2.tiff
            String[] s = fileName.split("_");
            Map<String, Object> params = new HashMap<>();
            HtScanningMetadataDTO metadataDTO = null;
            if ("GF1".equals(s[0]) || "GF6".equals(s[0])) {
                metadataDTO = htScanningMetadataService.findGF1(fileDate, s[1], "L1", s[0],
                        s[0], "GBAL", "xml");
            } else {
                String[] split = s[5].split("-");
                metadataDTO = htScanningMetadataService.findGF1(fileDate, s[1], "L1", s[0],
                        split[1].substring(0, 4), "GBAL", "X");
            }
            if (null == metadataDTO) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("primaryFile", primaryFile);
                params.put("geofile", taskPathParam.getParameter01() + metadataDTO.getFilePath());
                params.put("SSLRID", taskPathParam.getParameter02());
                params.put("WorkFlow", taskPathParam.getParameter03());
                params.put("Format", taskPathParam.getParameter09());
                params.put("ExportIMG", true);
                params.put("Region", taskPathParam.getParameter05());
                params.put("Bands", taskPathParam.getParameter04());
                params.put("ProjectionIdentify", "GLL");
                params.put("ExportAngles", Boolean.parseBoolean(taskPathParam.getParameter06()));
                params.put("IsOrtho", false);
                params.put("ExportDEM", Boolean.parseBoolean(taskPathParam.getParameter07()));
                params.put("Projection", Boolean.parseBoolean(taskPathParam.getParameter08()));
                params.put("Thumbnail", false);
                params.put("SingleBand", false);
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("FY3D_MERSI_L1_1000M".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            //FY3D_L1级原始数据预处理算法
            ///1000M/2023/20230701/FY3D_MERSI_GBAL_L1A_GLL_20230701_0905_1000M.nc
            HtScanningMetadataDTO metadataDTO = htScanningMetadataService.findOneByDate(fileDate, "L1", "FY3D",
                    "L1", "GBAL", "GEO1K");
            if (null == metadataDTO) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("geofile", taskPathParam.getParameter02() + metadataDTO.getFilePath());
                params.put("WorkFlow", taskPathParam.getParameter03());
                params.put("SSLRID", taskPathParam.getParameter04());
                params.put("Bands", taskPathParam.getParameter05());
                params.put("Region", taskPathParam.getParameter06());
                params.put("ProjectionIdentify", "GLL");
                params.put("Projection", true);
                params.put("SingleBand", false);
                params.put("Format", "NC");
                params.put("ExportIMG", true);
                params.put("ExportAngles", true);
                params.put("ExportDEM", true);
                params.put("Thumbnail", false);
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("FY4A_AGRI_L1_4000M".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            //FY4A_L1级原始数据预处理算法
            HtScanningMetadataDTO metadataDTO = htScanningMetadataService.findOneByDate(fileDate, "L1", "FY4A",
                    "GEO", "DISK", "GEO");
            if (null == metadataDTO) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("geofile", taskPathParam.getParameter02() + metadataDTO.getFilePath());
                params.put("WorkFlow", taskPathParam.getParameter03());
                params.put("SSLRID", taskPathParam.getParameter04());
                params.put("Bands", taskPathParam.getParameter05());
                params.put("Region", taskPathParam.getParameter06());
                params.put("ProjectionIdentify", "GLL");
                params.put("Projection", true);
                params.put("SingleBand", false);
                params.put("Format", "NC");
                params.put("ExportIMG", true);
                params.put("ExportAngles", true);
                params.put("ExportDEM", false);
                params.put("Thumbnail", false);
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("MODIS_L1_1000M".equals(adsType)) {
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] s1 = fileName.split("_");
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            //MODIS_L1级原始数据预处理算法
            //AQUA_X_2023_07_31_15_45_A_G.MOD021KM.hdf
            //TERRA_X_2023_07_31_11_51_D_G.MOD021KM.hdf
            HtScanningMetadataDTO metadataDTO = htScanningMetadataService.findByOrbitId(fileDate, "L1", s1[0],
                    "MOD03", "GBAL", "MOD03", s1[7]);
            if (null == metadataDTO) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("geofile", taskPathParam.getParameter02() + metadataDTO.getFilePath());
                params.put("WorkFlow", taskPathParam.getParameter03());
                params.put("SSLRID", taskPathParam.getParameter04());
                params.put("Region", taskPathParam.getParameter06());
                params.put("Format", "NC");
                params.put("ExportIMG", true);
                params.put("ExportAngles", true);
                params.put("ExportDEM", true);
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("H9_AHI_L1_2000M".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            params.put("geofile", null);
            params.put("Bands", taskPathParam.getParameter02());
            params.put("WorkFlow", taskPathParam.getParameter03());
            params.put("SSLRID", taskPathParam.getParameter04());
            params.put("Region", taskPathParam.getParameter06());
            params.put("Regions", JSONObject.parse("[{\n" +
                    "      \"Name\": \"REGC\",\n" +
                    "      \"MinX\": \"72\",\n" +
                    "      \"MaxX\": \"136\",\n" +
                    "      \"MinY\": \"17\",\n" +
                    "      \"MaxY\": \"55\"\n" +
                    "    }\n" +
                    "  ]"));
            params.put("Format", "NC");
            params.put("ProjectionIdentify", "GLL");
            params.put("Projection", true);
            params.put("ExportIMG", false);
            params.put("SingleBand", false);
            params.put("ExportAngles", true);
            params.put("ExportDEM", false);
            params.put("Thumbnail", false);
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("S2B_MSI_L1_20M".equals(adsType)) {
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] s1 = fileName.split("_");
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            //S2B_L1级原始数据预处理算法
            //T45RWM_20230718T043709_B01_20m.jp2
            params.put("SSLRID", taskPathParam.getParameter04());
            params.put("Region", s1[0]);
            params.put("ExportIMG", false);
            params.put("Projection", false);
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("LAD89_OLITIRS_L1_30M_L2SP".equals(adsType)) {
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] s1 = fileName.split("_");
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            //LAD89_L1级原始数据预处理算法
            //LC08_L2SP_133035_20221018_20221031_02_T1_SR_B1.TIF
            HtScanningMetadataDTO metadataDTO = htScanningMetadataService.findOneByDate(fileDate, s1[1], s1[0],
                    s1[0], "GBAL", "xml");
            if (null == metadataDTO) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("geofile", taskPathParam.getParameter02() + metadataDTO.getFilePath());
                params.put("SSLRID", taskPathParam.getParameter04());
                params.put("Region", taskPathParam.getParameter06());
                params.put("ExportIMG", false);
                params.put("Projection", false);
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("FIR".equals(adsType)) {
            //火情信息监测算法
            //H9_AHI_REGC_L1A_GLL_20231109_0320_2000M.NC
            Map<String, Object> params = new HashMap<>();
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] s1 = fileName.split("_");
            params.put("primaryFile", primaryFile);
            params.put("satellite", s1[0]);
            params.put("sensor", s1[1]);
            params.put("fileTime", s1[5] + s1[6] + "00");
            params.put("tempPath", taskPathParam.getParameter04());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("Tibet_Grass_GCT".equals(adsType)) {
            //GSE_GLCF_540000_L3_FY3D_MERSI_1000M_GLL_POAY_20220101000000_20221231000000.TIFF
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] s1 = fileName.split("_");
            String moduleIid = s1[0];
            String productMode = s1[8];
            String startTime = s1[9];
            Date date = DateUtil.parse(startTime, "yyyyMMddHHmmss");
            Date dateTime = DateUtil.offsetMonth(date, -12);
            String dateTimeStr = DateUtil.format(dateTime, "yyyyMMddHHmmss");
            HtScanningMetadataDTO metadataDTO = htScanningMetadataService.findMeatedataByMoudel(dateTimeStr, taskPathParam.getParameter04(), taskPathParam.getParameter07(),
                    taskPathParam.getParameter05(), taskPathParam.getParameter06(), productMode, moduleIid, taskPathParam.getParameter08());
            if (null == metadataDTO) {
                algorithmParams.put("parameter01", null);
            } else {
                String lastFile = taskPathParam.getParameter02() + metadataDTO.getFilePath();
                params.put("lastFile", lastFile);
                params.put("auxPath", taskPathParam.getParameter03());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("Tibet_Grass_Mask".equals(adsType) || "Tibet_Wetland_Mask".equals(adsType)) {
            //草地产品掩膜或湿地产品掩膜
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            params.put("auxPath", taskPathParam.getParameter03());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("Tibet_Prod_COMB".equals(adsType)) {
            //草地_生物量_季年合成
            //GSE_FAGB_540000_L3_FY3D_MERSI_1000M_GLL_MOAM_20211101000000_20211130000000.TIFF
            String fileName = primaryFile.substring(primaryFile.lastIndexOf("/") + 1);
            String[] s1 = fileName.split("_");
            String moduleIid = s1[0];
            String prodcut = s1[1];
            String region = s1[2];
            String level = s1[3];
            String satellite = s1[4];
            String productMode = s1[8];
            List<HtScanningMetadataDTO> metadataDTOList = new ArrayList<>();
            if (taskPathParam.getParameter04().contains("AQ")) {
                String month = s1[9].substring(4, 6); // 假设月份信息在日期字符串的第5位和第6位
                String quarter = null;
                switch (month) {
                    case "03":
                    case "04":
                    case "05":
                        quarter = "1";
                        break;
                    case "06":
                    case "07":
                    case "08":
                        quarter = "2";
                        break;
                    case "09":
                    case "10":
                    case "11":
                        quarter = "3";
                        break;
                    case "12":
                    case "01":
                    case "02":
                        quarter = "4";
                        break;
                }
                String year = s1[9].substring(0, 4);
                String startTime = null, endTime = null;
                if ("1".equals(quarter)) {
                    startTime = year + "0301000000";
                    endTime = year + "0531235959";
                } else if ("2".equals(quarter)) {
                    startTime = year + "0601000000";
                    endTime = year + "0831235959";
                } else if ("3".equals(quarter)) {
                    startTime = year + "0901000000";
                    endTime = year + "1131235959";
                } else if ("4".equals(quarter)) {
                    startTime = year + "12000000";
                    int i = Integer.parseInt(year);
                    int nextYear = i + 1;
                    endTime = nextYear + "0231235959";
                }
                metadataDTOList = htScanningMetadataService.findOneByDate(startTime, endTime, level, satellite,
                        prodcut.replace("-", ""), region, productMode, moduleIid, "TIFF");
                List<String> collect = metadataDTOList.stream().map(x -> taskPathParam.getParameter02() + File.separator + x.getFilePath()).collect(Collectors.toList());
                if (metadataDTOList.isEmpty()) {
                    algorithmParams.put("parameter01", null);
                } else {
                    Map<String, Object> params = new HashMap<>();
                    String join = StrUtil.join(",", collect);
                    params.put("primaryFile", join);
                    params.put("CType", taskPathParam.getParameter04());
                    params.put("auxPath", taskPathParam.getParameter03());
                    algorithmParams.put("parameter00", adsType);
                    algorithmParams.put("parameter01", params);
                }
            } else if (taskPathParam.getParameter04().contains("AY")) {
                //BAS_NDVI_540000_L3_FY3D_MERSI_1000M_GLL_MOAD_20230701000000_20230701235959.TIFF
                String date = s1[9].substring(0, 4);
                String startTime = date + "0101000000";
                String endTime = date + "1231235959";
                metadataDTOList = htScanningMetadataService.findOneByDate(startTime, endTime, level, satellite,
                        prodcut.replace("-", ""), region, productMode, moduleIid, "TIFF");
                List<String> collect = metadataDTOList.stream().map(x -> taskPathParam.getParameter02() + File.separator + x.getFilePath()).collect(Collectors.toList());
                if (metadataDTOList.isEmpty()) {
                    algorithmParams.put("parameter01", null);
                } else {
                    Map<String, Object> params = new HashMap<>();
                    String join = StrUtil.join(",", collect);
                    params.put("primaryFile", join);
                    params.put("CType", taskPathParam.getParameter04());
                    params.put("auxPath", taskPathParam.getParameter03());
                    algorithmParams.put("parameter00", adsType);
                    algorithmParams.put("parameter01", params);
                }
            }
        } else if ("XIZANG_FOR_DIFFJ".equals(adsType)) {
            //森林历史同期算法
            Map<String, Object> params = new HashMap<>();
            //GSE_PLIJ_540000_L3_FY3D_MERSI_1000M_GLL_MOAD_20210701000000_20210701235959.TIFF
            params.put("primaryFile", primaryFile);
            String fileName = primaryFile.substring(primaryFile.lastIndexOf("/") + 1);
            String[] s1 = fileName.split("_");
            String moduleIid = s1[0];
            String level = s1[3];
            String satellite = s1[4];
            String product = s1[1];
            String productMode = s1[8];
            String region = s1[2];
            String dataTime = DateUtils.getDateStr(primaryFile, "(\\d{14})");
            Date date = DateUtil.parse(dataTime, "yyyyMMddHHmmss");
            Date endTime = DateUtil.offsetDay(date, -1);
            String endTimeStr = DateUtil.format(endTime, "yyyyMMddHHmmss");
            Date startTime = DateUtil.offsetMonth(date, -60);
            String dateTimeStr = DateUtil.format(startTime, "yyyyMMddHHmmss");
            List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findOneByDate(dateTimeStr, endTimeStr, level, satellite,
                    product.replace("-", ""), region, productMode, moduleIid, "TIFF");
            List<String> collect = metadataDTOList.stream()
                    .sorted(Comparator.comparing(HtScanningMetadataDTO::getFileDate))
                    .map(x -> taskPathParam.getParameter02() + File.separator + x.getFilePath())
                    .collect(Collectors.toList());
            String join = StrUtil.join(",", collect);
            if (metadataDTOList.size() == 0) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("primaryFile", primaryFile);
                params.put("lastFile", join);
                params.put("satelliteName", satellite);
                params.put("auxPath", taskPathParam.getParameter03());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("XIZANG_FOR_DIFFT".equals(adsType)) {
            //森林去年同期算法
            // BAS_NDVI_540000_L3_FY3D_MERSI_1000M_GLL_MOAM_20210701000000_20210731000000.TIFF
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            String fileName = primaryFile.substring(primaryFile.lastIndexOf("/") + 1);
            String fileType = primaryFile.substring(primaryFile.lastIndexOf(".") + 1);
            String[] s1 = fileName.split("_");
            String moduleIid = s1[0];
            String level = s1[3];
            String satellite = s1[4];
            String productMode = s1[8];
            String region = s1[2];
            String dateStr = DateUtils.getDateStr(primaryFile, "(\\d{14})");
            Date date = DateUtil.parse(dateStr, "yyyyMMddHHmmss");
            Date dateTime = DateUtil.offsetMonth(date, -12);
            String dateTimeStr = DateUtil.format(dateTime, "yyyyMMddHHmmss");
            HtScanningMetadataDTO metadataDTO = htScanningMetadataService.findMetadataByParam
                    (dateTimeStr, level, satellite, taskPathParam.getParameter04(), region, productMode, moduleIid, fileType);
            if (null == metadataDTO) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("lastFile", taskPathParam.getParameter02() + metadataDTO.getFilePath());
                params.put("auxPath", taskPathParam.getParameter03());
                params.put("satelliteName", satellite);
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("Tibet_Grass_PTB".equals(adsType) || "Tibet_Wetland_PTB".equals(adsType)) {
            //草地去年同期算法 或 湿地去年同期
            // BAS_NDVI_540000_L3_FY3D_MERSI_1000M_GLL_MOAM_20210701000000_20210731000000.TIFF
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            String fileName = primaryFile.substring(primaryFile.lastIndexOf("/") + 1);
            String fileType = primaryFile.substring(primaryFile.lastIndexOf(".") + 1);
            String[] s1 = fileName.split("_");
            String moduleIid = s1[0];
            String level = s1[3];
            String satellite = s1[4];
            String productMode = s1[8];
            String region = s1[2];
            String dateStr = DateUtils.getDateStr(primaryFile, "(\\d{14})");
            Date date = DateUtil.parse(dateStr, "yyyyMMddHHmmss");
            Date dateTime = DateUtil.offsetMonth(date, -12);
            String dateTimeStr = DateUtil.format(dateTime, "yyyyMMddHHmmss");
            HtScanningMetadataDTO metadataDTO = htScanningMetadataService.findMetadataByParam(dateTimeStr, level, satellite, taskPathParam.getParameter04(), region, productMode, moduleIid, fileType);
            if (null == metadataDTO) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("lastFile", taskPathParam.getParameter02() + metadataDTO.getFilePath());
                params.put("auxPath", taskPathParam.getParameter03());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("Tibet_Grass_PJP".equals(adsType) || "Tibet_Wetland_PJP".equals(adsType)) {
            //草地历史同期算法 或 湿地历史同期算法
            Map<String, Object> params = new HashMap<>();
            //GSE_PLIJ_540000_L3_FY3D_MERSI_1000M_GLL_MOAD_20210701000000_20210701235959.TIFF
            params.put("primaryFile", primaryFile);
            String fileName = primaryFile.substring(primaryFile.lastIndexOf("/") + 1);
            String[] s1 = fileName.split("_");
            String moduleIid = s1[0];
            String level = s1[3];
            String satellite = s1[4];
            String product = s1[1];
            String productMode = s1[8];
            String region = s1[2];
            String dataTime = DateUtils.getDateStr(primaryFile, "(\\d{14})");
            Date date = DateUtil.parse(dataTime, "yyyyMMddHHmmss");
            Date endTime = DateUtil.offsetDay(date, -1);
            String endTimeStr = DateUtil.format(endTime, "yyyyMMddHHmmss");

            Date startTime = DateUtil.offsetMonth(date, -60);
            String dateTimeStr = DateUtil.format(startTime, "yyyyMMddHHmmss");
            List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findOneByDate(dateTimeStr, endTimeStr, level, satellite,
                    product.replace("-", ""), region, productMode, moduleIid, "TIFF");
            List<String> collect = metadataDTOList.stream()
                    .sorted(Comparator.comparing(HtScanningMetadataDTO::getFileDate))
                    .map(x -> taskPathParam.getParameter02() + File.separator + x.getFilePath())
                    .collect(Collectors.toList());
            String join = StrUtil.join(",", collect);
            if (metadataDTOList.size() == 0) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("primaryFile", primaryFile);
                params.put("lastFile", join);
                params.put("auxPath", taskPathParam.getParameter03());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("DIST".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            //GSE_PLIJ_540000_L3_FY3D_MERSI_1000M_GLL_MOAD_20210701000000_20210701235959.TIFF
            params.put("primaryFile", primaryFile);
            String fileName = primaryFile.substring(primaryFile.lastIndexOf("/") + 1);
            String[] s1 = fileName.split("_");
            String moduleIid = s1[0];
            String level = s1[3];
            String satellite = s1[4];
            String product = s1[1];
            String productMode = s1[8];
            String region = s1[2];
            String endTime = DateUtils.getDateStr(primaryFile, "(\\d{14})");
            Date date = DateUtil.parse(endTime, "yyyyMMddHHmmss");
            Date startTime = DateUtil.offsetMonth(date, -60);
            String dateTimeStr = DateUtil.format(startTime, "yyyyMMddHHmmss");
            List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findOneByDate(dateTimeStr, endTime, level, satellite,
                    product.replace("-", ""), region, productMode, moduleIid, "TIFF");
            List<String> collect = metadataDTOList.stream()
//                    .sorted(Comparator.comparing(HtScanningMetadataDTO::getFileDate))
                    .map(x -> taskPathParam.getParameter02() + File.separator + x.getFilePath())
                    .collect(Collectors.toList());
            String join = StrUtil.join(",", collect);
            if (metadataDTOList.size() < 2) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("primaryFile", primaryFile);
                params.put("historicalyearFile", join);
                params.put("auxPath", taskPathParam.getParameter03());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("Tibet_Grass_CVC".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] s = fileName.split("_");
            String year = s[9].substring(0, 4);
            String moduleIid = s[0];
            String productMode = s[8];
            String startTime = year + "0501000000";
            String endTime = year + "0930000000";
            List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findOneByDate(startTime, endTime, taskPathParam.getParameter04(), taskPathParam.getParameter07(),
                    taskPathParam.getParameter05(), taskPathParam.getParameter06(), productMode, moduleIid, "TIFF");
            List<String> collect = metadataDTOList.stream().map(x -> taskPathParam.getParameter02() + File.separator + x.getFilePath()).collect(Collectors.toList());
            String join = StrUtil.join(",", collect);
            params.put("primaryFile", join);
            params.put("auxPath", taskPathParam.getParameter03());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("Tibet_Grass_GCF".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] s = fileName.split("_");
            String year = s[9].substring(0, 4);
            String moduleIid = s[0];
            String productMode = s[8];
            String startTime = year + "0501000000";
            String endTime = year + "0930000000";
            List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findOneByDate(startTime, endTime, taskPathParam.getParameter04(), taskPathParam.getParameter07(),
                    taskPathParam.getParameter05(), taskPathParam.getParameter06(), productMode, moduleIid, taskPathParam.getParameter08());
            List<String> collect = metadataDTOList.stream().map(x -> taskPathParam.getParameter02() + File.separator + x.getFilePath()).collect(Collectors.toList());
            String join = StrUtil.join(",", collect);
            params.put("primaryFile", join);
            params.put("lcFile", "/work/tibet/parm/landcover/xizang_lc_2022.tif");
            params.put("auxPath", taskPathParam.getParameter03());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("Tibet_Grass_GSL".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] s = fileName.split("_");
            String moduleIid = s[0];
            String productMode = s[8];
            params.put("primaryFile", primaryFile);
            HtScanningMetadataDTO metadataDTO = htScanningMetadataService.findMeatedataByMoudel(s[9], taskPathParam.getParameter04(), taskPathParam.getParameter07(),
                    taskPathParam.getParameter05(), taskPathParam.getParameter06(), productMode, moduleIid, taskPathParam.getParameter08());
            params.put("lastFile", taskPathParam.getParameter02() + File.separator + metadataDTO.getFilePath());
            params.put("auxPath", taskPathParam.getParameter03());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("Tibet_Grass_SOS".equals(adsType) || "Tibet_Grass_EOS".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] s = fileName.split("_");
            String year = s[9].substring(0, 4);
            String moduleIid = s[0];
            String productMode = s[8];
            String startTime = year + "0101000000";
            String endTime = year + "1231000000";
            params.put("primaryFile", primaryFile);
            List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findOneByDate(startTime, endTime, taskPathParam.getParameter04(), taskPathParam.getParameter07(),
                    taskPathParam.getParameter05(), taskPathParam.getParameter06(), productMode, moduleIid, taskPathParam.getParameter08());
            List<String> collect = metadataDTOList.stream().map(x -> taskPathParam.getParameter02() + File.separator + x.getFilePath()).collect(Collectors.toList());
            String join = StrUtil.join(",", collect);
            params.put("primaryFile", join);
            params.put("nowDate", year);
            params.put("auxPath", taskPathParam.getParameter03());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("Tibet_Grass_PGA".equals(adsType)) {
            //禁牧区草地植被指数算法
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            params.put("auxPath", taskPathParam.getParameter03());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("Tibet_Grass_AGB".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            params.put("auxPath", taskPathParam.getParameter03());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("Tibet_Grass_FAGB".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            params.put("auxPath", taskPathParam.getParameter03());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("XIZANG_VSWI".equals(adsType)) {
            //BAS_NDVI_540000_L3_FY3D_MERSI_1000M_GLL_MOTD_20230701000000_20230710000000.TIFF
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] split = fileName.split("_");
            //String productMode = split[8];
            String region = split[2];
            String level = split[3];
            String moduleIid = split[0];
            String startTime = split[9];
            HtScanningMetadataDTO metadataDTO = htScanningMetadataService.findMetadataByParam(startTime, level, taskPathParam.getParameter03(),
                    taskPathParam.getParameter05(), region, taskPathParam.getParameter06(), moduleIid, taskPathParam.getParameter07());
            if (null == metadataDTO) {
                algorithmParams.put("parameter01", null);
            } else {
                Map<String, Object> params = new HashMap<>();
                params.put("primaryFile", primaryFile);
                params.put("auxPath", taskPathParam.getParameter02());
                params.put("satID", taskPathParam.getParameter03());
                params.put("L2File", taskPathParam.getParameter04() + metadataDTO.getFilePath());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }

        } else if ("XIZANG_TCI".equals(adsType) || "XIZANG_VCI".equals(adsType)) {

            //BAS_LST-_540000_L3_FY3D_MERSI_1000M_GLL_AOTD_20230701055000_20230710080500.TIFF
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            params.put("auxPath", taskPathParam.getParameter02());
            params.put("satID", taskPathParam.getParameter03());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("XIZANG_SPI_MCI".equals(adsType)) {
            //SURF_CHN_MUL_DAY_20220101000000.json
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] split = fileName.split("_");
            String endTime = split[4].replace(".json", "");
            //根据endTime字符串，往前推160天，得出startTime
            Date date = DateUtil.parse(endTime, "yyyyMMddHHmmss");
            Date dateTime = DateUtil.offsetDay(date, -159);
            String startTime = DateUtil.format(dateTime, "yyyyMMddHHmmss");
            String productMode = split[2];
            String productIid = split[0];
            String region = split[1];
            String level = split[3];
            List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findByMetadata(startTime, endTime, level, "FY3D", productIid, region, productMode, "JSON");
            if (metadataDTOList.size() < 160) {
                algorithmParams.put("parameter01", null);
            } else {
                //将文件名生成集合
                List<String> collect = metadataDTOList.stream().map(x -> scanningPath + x.getFilePath()).collect(Collectors.toList());
                Map<String, Object> params = new HashMap<>();
                params.put("primaryFile", collect);
                params.put("auxPath", taskPathParam.getParameter02());
                algorithmParams.put("parameter01", params);
            }
            algorithmParams.put("parameter00", adsType);
        } else if ("XIZANG_MID_ALG".equals(adsType)) {
            //鼠虫灾害监测评估算法
            Map<String, Object> params = new HashMap<>();
            String fileName = primaryFile.substring(primaryFile.lastIndexOf("/") + 1);
            String[] s1 = fileName.split("_");
            String moduleIid = s1[0];
            String level = s1[3];
            String satellite = s1[4];
            String product = s1[1];
            String productMode = s1[8];
            String region = s1[2];
            String endTime = DateUtils.getDateStr(primaryFile, "(\\d{14})");
            Date date = DateUtil.parse(endTime, "yyyyMMddHHmmss");
            Date startTime = DateUtil.offsetMonth(date, -60);
            String dateTimeStr = DateUtil.format(startTime, "yyyyMMddHHmmss");
            List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findOneByDate(dateTimeStr, endTime, level, satellite,
                    product.replace("-", ""), region, productMode, moduleIid, "TIFF");
            List<String> collect = metadataDTOList.stream().map(x -> taskPathParam.getParameter02() + File.separator + x.getFilePath()).collect(Collectors.toList());
            String join = StrUtil.join(",", collect);
            if (metadataDTOList.size() == 0) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("primaryFile", join);
                params.put("satelliteName", satellite);
                params.put("baseTime", endTime.substring(0, 8));
                params.put("auxPath", taskPathParam.getParameter03());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("WSCI".equals(adsType)) {
            Map<String, Object> params = new HashMap<>();
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] s1 = fileName.split("_");
            String year = s1[9].substring(0, 4);
            String moduleIid = s1[0];
            String productMode = s1[8];
            String level = s1[3];
            String satellite = s1[4];
            String product = s1[1];
            String region = s1[2];
            String startTime = year + "0501000000";
            String endTime = year + "0930000000";
            //查询NDVI5-9月的月合成数据
            List<HtScanningMetadataDTO> ndviList = htScanningMetadataService.findOneByDate(startTime, endTime, level, satellite,
                    product, region, productMode, moduleIid, "TIFF");
            List<String> ndviFileList = ndviList.stream().map(x -> taskPathParam.getParameter02() + File.separator + x.getFilePath()).collect(Collectors.toList());
            String ndviJoinList = StrUtil.join(",", ndviFileList);
            //查询NPP5-9月的月合成数据
            List<HtScanningMetadataDTO> nppList = htScanningMetadataService.findOneByDate(startTime, endTime, level, satellite,
                    "NPP", region, "POAM", "FOR", "TIFF");
            List<String> nppFileList = nppList.stream().map(x -> taskPathParam.getParameter02() + File.separator + x.getFilePath()).collect(Collectors.toList());
            String nppJoinList = StrUtil.join(",", nppFileList);

            Date date = DateUtil.parse(endTime, "yyyyMMddHHmmss");
            Date start = DateUtil.offsetMonth(date, -60);
            String dateTimeStr = DateUtil.format(start, "yyyyMMddHHmmss");
            //查询NPP五年的的年合成数据
            List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findOneByDate(dateTimeStr, endTime, level, satellite,
                    "NPP", region, "POAY", "FOR", "TIFF");

            List<String> collect = metadataDTOList.stream().map(x -> taskPathParam.getParameter02() + File.separator + x.getFilePath()).collect(Collectors.toList());
            String join = StrUtil.join(",", collect);

            if (ndviList.size() < 5 || nppList.size() < 5 || metadataDTOList.size() < 2) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("ndviM59MFile", ndviJoinList);
                params.put("nppP59MFile", nppJoinList);
                params.put("nppPO5YFile", join);
                params.put("satelliteName", satellite);
                params.put("auxPath", taskPathParam.getParameter03());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }

        } else if ("WSFI".equals(adsType)) {
            //ECQ-WSFI防风固沙指数计算
            Map<String, Object> params = new HashMap<>();
            String fileName = primaryFile.substring(primaryFile.lastIndexOf("/") + 1);
            String[] s1 = fileName.split("_");
            String level = s1[3];
            String satellite = s1[4];
            String region = s1[2];
            String endTime = s1[9];
            Date date = DateUtil.parse(endTime, "yyyyMMddHHmmss");
            Date startTime = DateUtil.offsetMonth(date, -60);
            String dateTimeStr = DateUtil.format(startTime, "yyyyMMddHHmmss");
            List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findOneByDate(dateTimeStr, endTime, level, satellite,
                    "NPP", region, "POAY", "FOR", "TIFF");

            List<String> collect = metadataDTOList.stream().map(x -> {
                if (x.getFileDate().equals(endTime)) {
                    params.put("nppPOAYFile", taskPathParam.getParameter02() + File.separator + x.getFilePath());
                }
                return taskPathParam.getParameter02() + File.separator + x.getFilePath();
            }).collect(Collectors.toList());
            String join = StrUtil.join(",", collect);
            if (metadataDTOList.size() < 2 || StringUtils.isEmpty(params.get("nppPOAYFile").toString())) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("ndviMOAYFile", primaryFile);
                params.put("nppPO5YFile", join);
                params.put("satelliteName", satellite);
                params.put("auxPath", taskPathParam.getParameter03());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("RSEI".equals(adsType)) {
            //ECQ-RSEI遥感生态指数计算
            Map<String, Object> params = new HashMap<>();
            String fileName = primaryFile.substring(primaryFile.lastIndexOf("/") + 1);
            String[] s1 = fileName.split("_");
            String level = s1[3];
            String satellite = s1[4];
            String region = s1[2];
            String startTime = s1[9];
            List<String> productList = Stream.of("WI", "DI", "GI", "HI", "WSCI", "EVCI", "WSFI").collect(Collectors.toList());
            List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findListLikeProductMode(startTime, level, satellite,
                    productList, region, "AY", "ECQ", "TIFF");

            List<String> collect = metadataDTOList.stream().map(x -> taskPathParam.getParameter02() + File.separator + x.getFilePath()).collect(Collectors.toList());
            String join = StrUtil.join(",", collect);
            if (metadataDTOList.size() == 7) {
                params.put("satelliteName", satellite);
                params.put("year", startTime.substring(0, 4));
                params.put("primaryFile", join);
                params.put("auxPath", taskPathParam.getParameter03());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            } else {
                algorithmParams.put("parameter01", null);
            }
        } else if ("GF_WER_CLSS".equals(adsType)) {
            //GF1_WFV1_GBAL_L1F_GLL_20230624_122115_0016M_MSS.TIFF
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            params.put("auxPath", taskPathParam.getParameter03());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        } else if ("Tibet_Grass_WYS".equals(adsType)) {
            //物候期年际变化算法
            Map<String, Object> params = new HashMap<>();
            String fileName = primaryFile.substring(primaryFile.lastIndexOf("/") + 1);
            String[] s1 = fileName.split("_");
            String moduleIid = s1[0];
            String level = s1[3];
            String satellite = s1[4];
            String product = s1[1];
            String productMode = s1[8];
            String region = s1[2];
            String endTime = DateUtils.getDateStr(primaryFile, "(\\d{14})");
            Date date = DateUtil.parse(endTime, "yyyyMMddHHmmss");
            Date startTime = DateUtil.offsetMonth(date, -60);
            String dateTimeStr = DateUtil.format(startTime, "yyyyMMddHHmmss");
            List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findOneByDate(dateTimeStr, endTime, level, satellite,
                    product.replace("-", ""), region, productMode, moduleIid, "TIFF");
            List<String> collect = metadataDTOList.stream().map(x -> taskPathParam.getParameter02() + File.separator + x.getFilePath()).collect(Collectors.toList());
            String join = StrUtil.join(",", collect);
            if (metadataDTOList.size() == 0) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("primaryFile", join);
                params.put("nowDate", endTime.substring(0, 4));
                params.put("auxPath", taskPathParam.getParameter03());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("Tibet_CIA".equals(adsType) ) {
            //天擎_气象要素_插值
            //SURF_CHN_MUL_DAY_20220101000000.json
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] s = fileName.split("_");
            String dateTime = s[4].substring(0,s[4].lastIndexOf("."));
            Map<String, Object> params = new HashMap<>();
            String startTime = dateTime;
            String endTime = dateTime;
            if (taskPathParam.getParameter04().contains("TD")) {
                if ("10".equals(startTime.substring(6, 8))) {
                    startTime = startTime.substring(0, 6) + "01" + startTime.substring(8);
                } else if ("20".equals(startTime.substring(6, 8))) {
                    startTime = startTime.substring(0, 6) + "11" + startTime.substring(8);
                } else if (Integer.parseInt(startTime.substring(6, 8)) >= 28) {
                    startTime = startTime.substring(0, 6) + "21" + startTime.substring(8);
                }
            } else if (taskPathParam.getParameter04().contains("AM")) {
                String date = dateTime.substring(0, 6);
                 startTime = date + "01000000";
                 endTime = date + "31235959";
            } else if (taskPathParam.getParameter04().contains("AQ")) {
                String month = dateTime.substring(4, 6); // 假设月份信息在日期字符串的第5位和第6位
                String quarter = null;
                switch (month) {
                    case "03":
                    case "04":
                    case "05":
                        quarter = "1";
                        break;
                    case "06":
                    case "07":
                    case "08":
                        quarter = "2";
                        break;
                    case "09":
                    case "10":
                    case "11":
                        quarter = "3";
                        break;
                    case "12":
                    case "01":
                    case "02":
                        quarter = "4";
                        break;
                }
                String year = dateTime.substring(0, 4);

                if ("1".equals(quarter)) {
                    startTime = year + "0301000000";
                    endTime = year + "0531235959";
                } else if ("2".equals(quarter)) {
                    startTime = year + "0601000000";
                    endTime = year + "0831235959";
                } else if ("3".equals(quarter)) {
                    startTime = year + "0901000000";
                    endTime = year + "1131235959";
                } else if ("4".equals(quarter)) {
                    startTime = year + "12000000";
                    int i = Integer.parseInt(year);
                    int nextYear = i + 1;
                    endTime = nextYear + "0231235959";
                }
            } else if (taskPathParam.getParameter04().contains("AY")) {
                //BAS_NDVI_540000_L3_FY3D_MERSI_1000M_GLL_MOAD_20230701000000_20230701235959.TIFF
                String date = dateTime.substring(0, 4);
                 startTime = date + "0101000000";
                 endTime = date + "1231235959";
            }
            List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findQxSite(startTime, endTime, s[3], "FY3D",
                    s[0].replace("-", ""), s[1],  "JSON");
            List<String> collect = metadataDTOList.stream().map(x -> scanningPath + File.separator + x.getFilePath()).collect(Collectors.toList());
            String join = StrUtil.join(",", collect);
            if (metadataDTOList.size() == 0) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("primaryFile", join);
                params.put("auxPath", taskPathParam.getParameter03());
                params.put("CType", taskPathParam.getParameter04());
                params.put("ProdID", taskPathParam.getParameter05());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        } else if ("Tibet_CTB".equals(adsType)) {
            //天擎_气象要素_插值去年同期
            //SURF_CHN_MUL_DAY_20220101000000.json
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] s = fileName.split("_");
            String dateTime = s[4].substring(0,s[4].lastIndexOf("."));
            Map<String, Object> params = new HashMap<>();
            String startTime = dateTime;
            String endTime = dateTime;
            if (taskPathParam.getParameter04().contains("TD")) {
                if ("10".equals(startTime.substring(6, 8))) {
                    startTime = startTime.substring(0, 6) + "01" + startTime.substring(8);
                } else if ("20".equals(startTime.substring(6, 8))) {
                    startTime = startTime.substring(0, 6) + "11" + startTime.substring(8);
                } else if (Integer.parseInt(startTime.substring(6, 8)) >= 28) {
                    startTime = startTime.substring(0, 6) + "21" + startTime.substring(8);
                }
            } else if (taskPathParam.getParameter04().contains("AM")) {
                String date = dateTime.substring(0, 6);
                startTime = date + "01000000";
                endTime = date + "31235959";
            } else if (taskPathParam.getParameter04().contains("AQ")) {
                String month = dateTime.substring(4, 6); // 假设月份信息在日期字符串的第5位和第6位
                String quarter = null;
                switch (month) {
                    case "03":
                    case "04":
                    case "05":
                        quarter = "1";
                        break;
                    case "06":
                    case "07":
                    case "08":
                        quarter = "2";
                        break;
                    case "09":
                    case "10":
                    case "11":
                        quarter = "3";
                        break;
                    case "12":
                    case "01":
                    case "02":
                        quarter = "4";
                        break;
                }
                String year = dateTime.substring(0, 4);
                if ("1".equals(quarter)) {
                    startTime = year + "0301000000";
                    endTime = year + "0531235959";
                } else if ("2".equals(quarter)) {
                    startTime = year + "0601000000";
                    endTime = year + "0831235959";
                } else if ("3".equals(quarter)) {
                    startTime = year + "0901000000";
                    endTime = year + "1131235959";
                } else if ("4".equals(quarter)) {
                    startTime = year + "12000000";
                    int i = Integer.parseInt(year);
                    int nextYear = i + 1;
                    endTime = nextYear + "0231235959";
                }
            } else if (taskPathParam.getParameter04().contains("AY")) {
                //BAS_NDVI_540000_L3_FY3D_MERSI_1000M_GLL_MOAD_20230701000000_20230701235959.TIFF
                String date = dateTime.substring(0, 4);
                startTime = date + "0101000000";
                endTime = date + "1231235959";
            }
            Date startTimeDate = DateUtil.parse(startTime, "yyyyMMddHHmmss").toJdkDate();
            Date endTimeDate = DateUtil.parse(endTime, "yyyyMMddHHmmss").toJdkDate();
            Date   lastYearStartDate = DateUtil.offsetMonth(startTimeDate, -12).toJdkDate();
            Date   lastYearEndDate = DateUtil.offsetMonth(endTimeDate, -12).toJdkDate();
            String startTimeDateStr = DateUtil.format(lastYearStartDate, "yyyyMMddHHmmss");
            String endTimeDateStr = DateUtil.format(lastYearEndDate, "yyyyMMddHHmmss");
            List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findQxSite(startTime, endTime, s[3], "FY3D",
                    s[0].replace("-", ""), s[1],  "JSON");
            List<HtScanningMetadataDTO> lastYearDTOList = htScanningMetadataService.findQxSite(startTimeDateStr, endTimeDateStr, s[3], "FY3D",
                    s[0].replace("-", ""), s[1],  "JSON");
            List<String> collect = metadataDTOList.stream().map(x -> scanningPath + File.separator + x.getFilePath()).collect(Collectors.toList());
            List<String> lastYearList = lastYearDTOList.stream().map(x -> scanningPath + File.separator + x.getFilePath()).collect(Collectors.toList());
            String join = StrUtil.join(",", collect);
            String joinLastYera = StrUtil.join(",", lastYearList);
            if (metadataDTOList.size() == 0 || lastYearDTOList.size()==0) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("primaryFile", join);
                params.put("lastFile", joinLastYera);
                params.put("auxPath", taskPathParam.getParameter03());
                params.put("CType", taskPathParam.getParameter04());
                params.put("ProdID", taskPathParam.getParameter05());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        }else if ("Tibet_CJP".equals(adsType)) {
            //天擎_气象要素_插值历史同期
            //SURF_CHN_MUL_DAY_20220101000000.json
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] s = fileName.split("_");
            String dateTime = s[4].substring(0,s[4].lastIndexOf("."));
            Map<String, Object> params = new HashMap<>();
            String startTime = dateTime;
            String endTime = dateTime;
            if (taskPathParam.getParameter04().contains("TD")) {
                if ("10".equals(startTime.substring(6, 8))) {
                    startTime = startTime.substring(0, 6) + "01" + startTime.substring(8);
                } else if ("20".equals(startTime.substring(6, 8))) {
                    startTime = startTime.substring(0, 6) + "11" + startTime.substring(8);
                } else if (Integer.parseInt(startTime.substring(6, 8)) >= 28) {
                    startTime = startTime.substring(0, 6) + "21" + startTime.substring(8);
                }
            } else if (taskPathParam.getParameter04().contains("AM")) {
                String date = dateTime.substring(0, 6);
                startTime = date + "01000000";
                endTime = date + "31235959";
            } else if (taskPathParam.getParameter04().contains("AQ")) {
                String month = dateTime.substring(4, 6); // 假设月份信息在日期字符串的第5位和第6位
                String quarter = null;
                switch (month) {
                    case "03":
                    case "04":
                    case "05":
                        quarter = "1";
                        break;
                    case "06":
                    case "07":
                    case "08":
                        quarter = "2";
                        break;
                    case "09":
                    case "10":
                    case "11":
                        quarter = "3";
                        break;
                    case "12":
                    case "01":
                    case "02":
                        quarter = "4";
                        break;
                }
                String year = dateTime.substring(0, 4);
                if ("1".equals(quarter)) {
                    startTime = year + "0301000000";
                    endTime = year + "0531235959";
                } else if ("2".equals(quarter)) {
                    startTime = year + "0601000000";
                    endTime = year + "0831235959";
                } else if ("3".equals(quarter)) {
                    startTime = year + "0901000000";
                    endTime = year + "1131235959";
                } else if ("4".equals(quarter)) {
                    startTime = year + "12000000";
                    int i = Integer.parseInt(year);
                    int nextYear = i + 1;
                    endTime = nextYear + "0231235959";
                }
            } else if (taskPathParam.getParameter04().contains("AY")) {
                //BAS_NDVI_540000_L3_FY3D_MERSI_1000M_GLL_MOAD_20230701000000_20230701235959.TIFF
                String date = dateTime.substring(0, 4);
                startTime = date + "0101000000";
                endTime = date + "1231235959";
            }
            Date startTimeDate = DateUtil.parse(startTime, "yyyyMMddHHmmss").toJdkDate();
            Date endTimeDate = DateUtil.parse(endTime, "yyyyMMddHHmmss").toJdkDate();

            List<HtScanningMetadataDTO> historyList =new ArrayList<>();
            for (int i = 1; i <= 5; i++) {
                Date   lastYearStartDate = DateUtil.offsetMonth(startTimeDate, -(12*i)).toJdkDate();
                Date   lastYearEndDate = DateUtil.offsetMonth(endTimeDate, -(12*i)).toJdkDate();
                String startTimeDateStr = DateUtil.format(lastYearStartDate, "yyyyMMddHHmmss");
                String endTimeDateStr = DateUtil.format(lastYearEndDate, "yyyyMMddHHmmss");
                List<HtScanningMetadataDTO> lastYearDTOList = htScanningMetadataService.findQxSite(startTimeDateStr, endTimeDateStr, s[3], "FY3D",
                        s[0].replace("-", ""), s[1],  "JSON");
                historyList.addAll(lastYearDTOList);
            }
            List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findQxSite(startTime, endTime, s[3], "FY3D",
                    s[0].replace("-", ""), s[1],  "JSON");
            List<String> collect = metadataDTOList.stream().map(x -> scanningPath + File.separator + x.getFilePath()).collect(Collectors.toList());
            List<String> historyYearList = historyList.stream().map(x -> scanningPath + File.separator + x.getFilePath()).collect(Collectors.toList());
            String join = StrUtil.join(",", collect);
            String joinHistory = StrUtil.join(",", historyYearList);
            if (metadataDTOList.size() == 0 || historyYearList.size()==0) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("primaryFile", join);
                params.put("lastFile", joinHistory);
                params.put("auxPath", taskPathParam.getParameter03());
                params.put("CType", taskPathParam.getParameter04());
                params.put("ProdID", taskPathParam.getParameter05());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        }else if ("Tibet_Grass_RCP".equals(adsType)) {
            //天擎_气象要素_影响评估
            String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
            String[] s = fileName.split("_");
            String[] s1 = fileName.split("_");
            String level = s1[3];
            String satellite = s1[4];
            String region = s1[2];
            String startTime = s1[9]; //SURF_CHN_MUL_DAY_20220101000000.json
            String endTimeDateStr = s1[10];
            String productMode = s1[8];
            List<String> productList = Stream.of("NDVI", "EVI", "LAI", "FVC", "GPP", "NPP", "NEP").collect(Collectors.toList());
            List<HtScanningMetadataDTO> metadataDTOList = htScanningMetadataService.findListLikeProductMode(startTime, level, satellite,
                    productList, region, productMode.substring(2,4), "GSE", "TIFF");
            List<String> collect = metadataDTOList.stream().map(x -> taskPathParam.getParameter02() + File.separator + x.getFilePath()).collect(Collectors.toList());
            String join = StrUtil.join(",", collect);
            List<HtScanningMetadataDTO> obsFileList = htScanningMetadataService.findQxSite(startTime, endTimeDateStr, "DAY", "FY3D",
                   "SURF", "CHN",  "JSON");
            List<String> obsCollect = obsFileList.stream().map(x -> "/mnt/sfs/data" + File.separator + x.getFilePath()).collect(Collectors.toList());
            String joinObs = StrUtil.join(",", obsCollect);
            Map<String, Object> params = new HashMap<>();
            if (obsFileList.size() == 0) {
                algorithmParams.put("parameter01", null);
            } else {
                params.put("primaryFile", join);
                params.put("obsFile", joinObs);
                params.put("auxPath", taskPathParam.getParameter03());
                algorithmParams.put("parameter00", adsType);
                algorithmParams.put("parameter01", params);
            }
        }  else {
            Map<String, Object> params = new HashMap<>();
            params.put("primaryFile", primaryFile);
            params.put("auxPath", taskPathParam.getParameter02());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        }
        return algorithmParams;
    }

    private String checkVal(String value) {
        if (!StringUtils.isEmpty(value)) {
            return value;
        }
        return "";
    }


    /**
     * 获取要执行的文件
     *
     * @param sourceDate
     * @return
     */
    private boolean getFileMap(LocalDate
                                       sourceDate, Map<String, String> resultMap, Map<String, String> l3resultMap) {
        String primaryYear = String.valueOf(sourceDate.getYear());
        String l3Year = String.valueOf(sourceDate.minusYears(1).getYear());
        String filePath = FileUtil.getInstance().getDataFormatePath("/share/product/FY3D/NDVI00/|yyyy|/|yyyy|POAY", sourceDate);
        File sncFile = new File(filePath);
        if (!sncFile.exists()) {
            logger.error("执行算法失败，源文件不存在。{}", filePath);
            return false;
        }
        //获取文件
        File[] files = sncFile.listFiles(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                System.out.println(name);
                if (name.contains(".TIFF")) {
                    return true;
                }
                return false;
            }
        });
        if (files.length == 0) {
            logger.error("执行算法失败，目录{}下没有可执行的文件。", filePath);
            return false;
        }
        //解析文件，分组返回
        for (File file : files) {
            //FY3D_MERSI_GLL_NDVI00_2021_POAY_ARG--_MAIZE_1000M.TIFF
            ///FY3D_MERSI_GLL_NDVI00_2021_POAY_AUS--_WHEAT_1000M.TIFF
            //   0    1     2    3     4     5   6     7      8
            String[] namestr = file.getName().split("_");
            //按区域和作物类型分组
            String key = namestr[6].replace("--", "") + "_" + namestr[7];
//            System.out.println("测试=====primaryFile：" + key + ":" + file.getPath());
            resultMap.put(key, file.getPath());
            //获得L3文件
//            System.out.println("测试=====l3File：" + key + ":" + file.getPath().replace(primaryYear, l3Year));
            l3resultMap.put(key, file.getPath().replace(primaryYear, l3Year));
        }
        return true;
    }

    //如果是开始时间
    private static List<String[]> getFilesByTime(String filePath, String startTime, String endTime, String matche) {

        List<String[]> filePaths = new ArrayList<String[]>();
        List<String[]> truefilePaths = new ArrayList<String[]>();
        if (startTime.substring(0, 8).equals(endTime.substring(0, 8))) {
            //同一个文件夹的处理
            ///mnt/FY4DATA/AGRI/L1/FDI/DISK\\2021\\20210909
            String startFilePath = filePath + File.separator + startTime.substring(0, 4) + File.separator + startTime.substring(0, 8);
            filePaths.addAll(getFiles(startFilePath, matche));
        } else {
            String startFilePath = filePath + File.separator + startTime.substring(0, 4) + File.separator + startTime.substring(0, 8);
            String endFilePath = filePath + File.separator + endTime.substring(0, 4) + File.separator + endTime.substring(0, 8);
            filePaths.addAll(getFiles(startFilePath, matche));
            filePaths.addAll(getFiles(endFilePath, matche));
        }
        //比较时间是否在访问内
        for (String[] time : filePaths) {
            if (Long.valueOf(time[0]) >= Long.valueOf(startTime) && Long.valueOf(time[0]) < Long.valueOf(endTime)) {
                // filePaths.remove(time);
                truefilePaths.add(time);
            }
        }
        return truefilePaths;

    }

    //返回 时次  文件名 数组
    private static List<String[]> getFiles(String startFilePath, String matche) {
        List<String[]> filePaths = new ArrayList<String[]>();
        File startFileDir = new File(startFilePath);
        File[] startFiles = startFileDir.listFiles();
        if (startFiles == null) return filePaths;
        for (File file : startFiles) {
            //先匹配到文件
            String fn = FileUtil.getFileName(file.getAbsolutePath());
            //if(fn.matches(".*FDI.*4000M_V0001.HDF$")) { --matche
            if (fn.matches(matche)) {
                //匹配到文件
                String[] nameTime = new String[2];
                Pattern p = Pattern.compile("(\\d{4})(\\d{1,2})(\\d{1,2})(\\d{1,2})(\\d{1,2})(\\d{1,2})");
                Matcher m = p.matcher(fn);
                String time = "";
                while (m.find()) {
                    time = m.group();
                    break;
                }
                nameTime[0] = time;
                nameTime[1] = fn;
                filePaths.add(nameTime);
            }
        }
        return filePaths;
    }

    private void getclp(Map<String, Object> callParamterMap, String parameter, String time) {
        // //时间格式为 20190304230000
        String clp = (String) callParamterMap.get(parameter);
        //获取年月日

        String year = time.substring(0, 4);
        String moth = time.substring(0, 8);
        //获得L2级路径
        String l2FilePath = clp + "/" + year + "/" + moth;
        String filepath = "";
        File f = new File(l2FilePath);
        File[] fs = f.listFiles();
        for (File ff : fs) {
            String fn = FileUtil.getFileName(ff.getAbsolutePath());
            if (fn.contains(time) && fn.endsWith("4000M_V0001.NC")) {

                filepath = clp + "\\" + year + "\\" + moth + "\\" + fn;

                callParamterMap.put(parameter, filepath.replace("\\", "/"));
                break;
            }
        }

    }

    //检验源文件规则解析
    private String validationRule(String validationFile, String fileDate, String validationFile1) {
        StringBuilder filePathSb = new StringBuilder();
        if (StringUtils.isBlank(validationFile)) {
            return filePathSb.toString();
        }
        RuleVO ruleVO = JSON.parseObject(validationFile, RuleVO.class);
        if (NULL.equals(ruleVO.getMatchRule()) || NULL.equals(ruleVO.getLevel())) {
            return filePathSb.toString();
        }
        Map<String, String> timeRangeParam = parseTimeRange(fileDate, ruleVO.getTimeRange());
        String mathexp = ruleVO.getMatchRule();
        String satellite = ruleVO.getSatellite();
        String startTime = timeRangeParam.get("startTime");
        String endTime = timeRangeParam.get("endTime");
        List<DbDmsScanningValidationDTO> ruleFileList = dbDmsScanningValidationService
                .findBySatelliteAndDataLevelAndProductIdentifyAndFileDateBetween(satellite, ruleVO.getLevel(), mathexp, startTime, endTime);
        if (ruleFileList.isEmpty()) {
            logger.info("未查询到任何质检源数据文件");
            return null;
        }
        for (DbDmsScanningValidationDTO fileDTO : ruleFileList) {
            String currentFilePath = validationFile1 + File.separator + fileDTO.getFilePath();
            File file = new File(currentFilePath);
            if (!file.exists()) {
                logger.info("{}在磁盘上不存在", fileDTO.getFileName());
                return null;
            }
            filePathSb.append(",").append(currentFilePath);
        }

        return filePathSb.substring(1);
    }

    /**
     * @param inputParams 输入参数
     * @param ruleParams  规则参数
     * @param taskDTO     任务信息对象
     * @param data        处理的数据对象，自己定义
     */
    @Override
    public void parseRuleAndFindData(Map<String, Object> inputParams, Map<String, Object> ruleParams,
                                     HtScheduleJobDTO taskDTO, Object data) {
        HtScanningMetadataDTO metadataDTO = (HtScanningMetadataDTO) data;
        List<HtScanningMetadataDTO> dataList = new ArrayList<>();
        dataList.add(metadataDTO);
        AlgorithmTaskRuleParam taskRuleParam = JSON.parseObject(JSON.toJSONString(ruleParams), AlgorithmTaskRuleParam.class);
        AlgorithmTaskPathParam taskPathParam = JSON.parseObject(JSON.toJSONString(inputParams), AlgorithmTaskPathParam.class);
        assemble(taskRuleParam, taskPathParam, dataList, taskDTO);
    }

    private void assemble(AlgorithmTaskRuleParam taskRuleParam, AlgorithmTaskPathParam taskPathParam,
                          List<HtScanningMetadataDTO> dataList, HtScheduleJobDTO taskDTO) {
        assemble(taskRuleParam, taskPathParam, null, dataList, taskDTO);
    }

    /**
     * 校验输入规则的文件是否写入路径
     *
     * @param ruleParam
     * @param pathParam
     * @return
     */
    private boolean rulePathExist(AlgorithmTaskRuleParam ruleParam, AlgorithmTaskPathParam pathParam) {
        if (StringUtils.isBlank(ruleParam.getPrimaryFile())) {
            logger.info("主文件规则为空");
            return false;
        }
        /*if (StringUtils.isNotBlank(ruleParam.getGeoFile())) {
            RuleVO geoRuleVO = JSON.parseObject(ruleParam.getGeoFile(), RuleVO.class);
            if (!NULL.equals(geoRuleVO.getMatchRule()) && StringUtils.isBlank(pathParam.getGeoFile())) {
                logger.info("geo文件输入路径为空");
                return false;
            }
        }
        if (StringUtils.isNotBlank(ruleParam.getL2File())) {
            RuleVO l2RuleVO = JSON.parseObject(ruleParam.getL2File(), RuleVO.class);
            if (!NULL.equals(l2RuleVO.getMatchRule()) && StringUtils.isBlank(pathParam.getL2File())) {
                logger.info("L2文件输入路径为空");
                return false;
            }
        }
        if (StringUtils.isNotBlank(ruleParam.getNwpFile())) {
            RuleVO nwpRuleVO = JSON.parseObject(ruleParam.getNwpFile(), RuleVO.class);
            if (!NULL.equals(nwpRuleVO.getMatchRule()) && StringUtils.isBlank(pathParam.getNwpFile())) {
                logger.info("辅助（nwp）文件输入路径为空");
                return false;
            }
        }*/
        return true;
    }

    public static void main(String[] args) {
        String s1="SURF_CHN_MUL_DAY_20230920000000.json";
        String[] s = s1.split("_");
        String dateTime = s[4].substring(0,s[4].lastIndexOf("."));
        System.out.println(dateTime);
//                startTime = startTime.substring(0, 6) + "01" + startTime.substring(8);
    }

    private String getYearQuarterKey(String fileDate) {
        LocalDate date = LocalDate.parse(fileDate, TIME_FORMAT);
        int year = date.getYear();
        int quarter = (date.getMonthValue() - 1) / 3 + 1;
        return year + "-Q" + quarter;
    }

    protected List<HtScanningMetadataDTO> selectExecMainFileList(RuleVO primaryRuleVO, boolean preprocess,
                                                                 HtScheduleJobDTO taskDTO, String adsType, AlgorithmTaskPathParam taskPathParam) {
        //获取文件匹配规则
        if (StringUtils.isBlank(primaryRuleVO.getMatchRule()) || NULL.equals(primaryRuleVO.getMatchRule())) {
            new ArrayList<>();
        }
//        String mainMathexp = primaryRuleVO.getMatchRule().split(",|\\|")[0];
        String mainMathexp = primaryRuleVO.getMatchRule();
        //产品标识
        String productIdentify = primaryRuleVO.getProductIdentify();
        //任务类型
        String taskType = taskDTO.getTaskType();
        LocalDateTime now = LocalDateTime.now();
        //从算法执行时间往前推一百天
        Date redoStartTime = taskDTO.getRedoStartTime();
        Calendar cal = Calendar.getInstance();
        cal.setTime(redoStartTime);
        String startTime = TIME_FORMAT.format(cal.toInstant().atZone(ZoneId.systemDefault()));
//        String startTime = TIME_FORMAT.format(now.plusDays(-1L * nearDay));
        String endTime = TIME_FORMAT.format(now);
        Pattern p = Pattern.compile(mainMathexp);
        if ("redo_singleTask".equals(taskType)) {
//            Date redoStartTime = taskDTO.getRedoStartTime();
            Date redoEndTime = taskDTO.getRedoEndTime();
            Calendar cale = Calendar.getInstance();
            cale.setTime(redoEndTime);
//            startTime = TIME_FORMAT.format(redoStartTime.toInstant().atZone(ZoneId.systemDefault()));
            endTime = TIME_FORMAT.format(cale.toInstant().atZone(ZoneId.systemDefault()));
        }
        List<HtScanningMetadataDTO> metaDataList = null;
        List<HtScanningMetadataDTO> allMetaDataList = new ArrayList<>();
        /*
            预处理：根据传入的传感器，时间范围，数据等级查询。
            专业处理：根据传入的通道，时间范围，文件类型（L2X、L2Y的文件类型为TIFF），数据等级查询。
         */
        /*if (preprocess) {
            allMetaDataList = htScanningMetadataService.listBySensorAndRangeTimeAndLevel(mainMathexp,startTime,endTime,primaryRuleVO.getLevel());
        } else {
            allMetaDataList = htScanningMetadataService.listByBandsAndDataLevelAndProductIidAndRangeTime(mainMathexp,primaryRuleVO.getLevel(),productIdentify,startTime,endTime);
        }*/

        metaDataList = htScanningMetadataService.findByMetadata(startTime, endTime, primaryRuleVO.getLevel(), primaryRuleVO.getSatellite(), primaryRuleVO.getProductIdentify());

        for (HtScanningMetadataDTO dto : metaDataList) {
            Matcher matcher = p.matcher(dto.getFileName());
            if (matcher.matches()) {
                allMetaDataList.add(dto);
            }
        }
        if ("FY3D_MERSI_L3_1000M".equals(adsType) || "XIZANG_VEG".equals(adsType)) {
            //20231120
            Map<LocalDate, HtScanningMetadataDTO> result = allMetaDataList.stream()
                    .collect(Collectors.toMap(
                            x -> LocalDateTime.parse(x.getFileDate(), TIME_FORMAT).toLocalDate(),
                            x -> x,
                            (existing, replacement) -> existing
                    ));
            allMetaDataList = new ArrayList<>(result.values());
        } else if ("Tibet_Prod_COMB".equals(adsType)) {
            if (taskPathParam.getParameter04().contains("AY")) {
                Map<Integer, HtScanningMetadataDTO> result = allMetaDataList.stream()
                        .collect(Collectors.toMap(
                                x -> LocalDateTime.parse(x.getFileDate(), TIME_FORMAT).getYear(),
                                x -> x,
                                (existing, replacement) -> existing
                        ));
                allMetaDataList = new ArrayList<>(result.values());
            } else {
                Map<String, HtScanningMetadataDTO> result = allMetaDataList.stream()
                        .collect(Collectors.toMap(
                                x -> getYearQuarterKey(x.getFileDate()),
                                x -> x,
                                (existing, replacement) -> existing
                        ));
                allMetaDataList = new ArrayList<>(result.values());
            }
        }

        List<String> allNameList = allMetaDataList.stream().map(HtScanningMetadataDTO::getFileName).collect(Collectors.toList());

        List<DbDmsSchedulerTaskFileRecordDTO> existRecordDataList = dbDmsSchedulerTaskFileRecordService.findByTaskIdAndFileNameIn(taskDTO.getId(), allNameList);
        List<HtScanningMetadataDTO> execMetadataList = new ArrayList<>();
        if (existRecordDataList.isEmpty()) {
            execMetadataList.addAll(allMetaDataList);
        } else {
            Set<String> existingFiles = existRecordDataList.stream()
                    .map(DbDmsSchedulerTaskFileRecordDTO::getFileName)
                    .collect(Collectors.toSet());
            execMetadataList.addAll(allMetaDataList.stream()
                    .filter(dto -> !existingFiles.contains(dto.getFileName()))
                    .collect(Collectors.toList()));
        }

        return execMetadataList;
        //        List<HtScanningMetadataDTO> execMetadataList = null;
//        //过滤需要执行的主文件，如果记录表中为空则查询出的时间范围内所有文件都执行，如果不为空，则筛选掉已经执行过的。
//        if (existRecordDataList.isEmpty() && !"FY3D_MERSI_L3_1000M".equals(adsType)) {
//            execMetadataList = allMetaDataList;
//        } else if ("FY3D_MERSI_L3_1000M".equals(adsType)) {
//            Map<LocalDate, HtScanningMetadataDTO> result = execMetadataList.stream()
//                    .collect(Collectors.toMap(
//                            // 分组的键是按天截断的时间戳
//                            dto -> LocalDateTime.parse(dto.getFileDate(), TIME_FORMAT).toLocalDate(),
//                            // 值是每天的第一个元素
//                            dto -> dto,
//                            // 如果有重复的键，选择旧值（即保留每天的第一个元素）
//                            (existing, replacement) -> existing
//                    ));
//            execMetadataList=new ArrayList<>(result.values());
//        }else {
//            Map<String, DbDmsSchedulerTaskFileRecordDTO> hash = existRecordDataList.stream().
//                    collect(Collectors.toMap(DbDmsSchedulerTaskFileRecordDTO::getFileName, dto -> dto, (v1, v2) -> v2));
//            execMetadataList = allMetaDataList.stream().filter(dto -> !hash.containsKey(dto.getFileName())).collect(Collectors.toList());
//        }
//
//        return execMetadataList;


    }

    protected List<HtScanningMetadataDTO> findRedoMetadataList(String taskId) {
        List<DbDmsSchedulerTaskFileRecordDTO> redoTaskRecordList = dbDmsSchedulerTaskFileRecordService.findRedoTasks(taskId);
        List<String> fileNameList = redoTaskRecordList.stream()
                .map(DbDmsSchedulerTaskFileRecordDTO::getFileName).collect(Collectors.toList());
        return htScanningMetadataService.findByFileNameList(fileNameList);
    }

    private String primaryRule(RuleVO primaryFileRule, boolean preprocess, HtScanningMetadataDTO mainFileDTO,
                               HtPathConfigurationDTO pathDTO, String matchRule) {
        //主文件规则时间范围
        String mainFileDate = mainFileDTO.getFileDate();
        Map<String, String> timeRangeParam = parseTimeRange(mainFileDate, primaryFileRule.getTimeRange());
        //查找满足要求的所有文件列表
        String[] mathexpArr = matchRule.split("\\|");
        String leftTime = timeRangeParam.get("startTime");
        String rightTime = timeRangeParam.get("endTime");
        //如果没有输入时间参数，则默认考虑正负3分钟查找文件，经纬度满足正负0.5°
        if (leftTime.equals(rightTime)) {
            return findPrimaryFileList(mainFileDTO, primaryFileRule.getLevel(), pathDTO, Arrays.asList(mathexpArr), preprocess);
        } else {
            //1、根据主通道找到输入的时间范围内的所有主通道文件。2、根据不同时次的主通道正负3分钟找到同一谱段的其他通道文件，拼接
            List<HtScanningMetadataDTO> mainBandsFileList = htScanningMetadataService
                    .listByBandsAndDataLevelAndRangeTime(mainFileDTO.getBands(), primaryFileRule.getLevel(), leftTime, rightTime);
            if (mainBandsFileList.isEmpty()) {
                logger.info("未查询到多个谱段的主通道文件时");
                return null;
            }
            StringBuilder primaryFilePath = new StringBuilder();
            for (HtScanningMetadataDTO dto : mainBandsFileList) {
                String path = findPrimaryFileList(dto, primaryFileRule.getLevel(), pathDTO, Arrays.asList(mathexpArr), preprocess);
                if (path == null) {
                    return null;
                }
                primaryFilePath.append(";").append(path);
            }
            return primaryFilePath.substring(1);
        }
    }

    /**
     * 获取primaryFile文件列表信息
     *
     * @param mainFileDTO
     * @param level
     * @param bandsList
     * @return
     */
    private String findPrimaryFileList(HtScanningMetadataDTO mainFileDTO, String level, HtPathConfigurationDTO
            pathDTO,
                                       List<String> bandsList, boolean preProcess) {
        List<HtScanningMetadataDTO> resultList = null;
        //标准化处理
        if (preProcess) {
            resultList = new ArrayList<>();
            resultList.add(mainFileDTO);
        } else {
            String mainFileDate = mainFileDTO.getFileDate();
            String leftTime = TIME_FORMAT.format(LocalDateTime.parse(mainFileDate, TIME_FORMAT).plusMinutes(-1 * DIFF_TIME_MINUTE));
            String rightTime = TIME_FORMAT.format(LocalDateTime.parse(mainFileDate, TIME_FORMAT).plusMinutes(DIFF_TIME_MINUTE));
            List<HtScanningMetadataDTO> dataList = htScanningMetadataService
                    .listByBandsAndDataLevelRangeTime(bandsList, level, leftTime, rightTime);
            if (dataList.isEmpty()) {
                return null;
            }
            double lon = Double.parseDouble(mainFileDTO.getLon().substring(1));
            double lat = Double.parseDouble(mainFileDTO.getLat().substring(1));
            resultList = dataList.stream().filter(dto -> {
                double dLon = Double.parseDouble(dto.getLon().substring(1));
                double dLat = Double.parseDouble(dto.getLat().substring(1));
                return dLon >= lon - 0.5 && dLon <= lon + 0.5 && dLat >= lat - 0.5 && dLat <= lat + 0.5;
            }).collect(Collectors.toList());
            //校验查询出的数据是否和输入通道数量匹配
            Map<String, List<HtScanningMetadataDTO>> hash = resultList.stream().collect(Collectors.groupingBy(HtScanningMetadataDTO::getBands));
            if (hash.size() != bandsList.size()) {
                logger.info("查询出的通道数量与输入数量不匹配");
                return null;
            }
            List<HtScanningMetadataDTO> tempList = new ArrayList<>();
            long mainFileMilli = LocalDateTime.parse(mainFileDate, TIME_FORMAT).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
            hash.values().forEach(list -> {
                HtScanningMetadataDTO resultDTO = list.stream().min((a, b) -> {
                    long aMilli = LocalDateTime.parse(a.getFileDate(), TIME_FORMAT).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
                    long bMilli = LocalDateTime.parse(b.getFileDate(), TIME_FORMAT).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
                    return Math.abs(aMilli - mainFileMilli) > Math.abs(bMilli - mainFileMilli) ? 1 : -1;
                }).get();
                tempList.add(resultDTO);
            });
            resultList = tempList;
        }
        //判断磁盘上是否存在文件
        StringBuilder sb = new StringBuilder();
        for (HtScanningMetadataDTO dto : resultList) {
            String currentFilePath = pathDTO.getClientPath() + File.separator + dto.getFilePath();
            File file = new File(currentFilePath);
            if (!file.exists()) {
                return null;
            }
            sb.append(",").append(currentFilePath);
        }
        return sb.substring(1);
    }

    private Map<String, String> geoRule(String geoRule, boolean preProcess, HtScanningMetadataDTO
            mainFileDTO, String geoPathPrefix) {
        StringBuilder geoPathSb = new StringBuilder();
        StringBuilder rpbPathSb = new StringBuilder();
        Map<String, String> resultMap = new HashMap<>();
        resultMap.put("geo", "");
        resultMap.put("rpb", "");
        if (StringUtils.isBlank(geoRule)) {
            return resultMap;
        }
        RuleVO geoRuleVO = JSON.parseObject(geoRule, RuleVO.class);
        if (NULL.equals(geoRuleVO.getMatchRule()) || NULL.equals(geoRuleVO.getLevel())) {
            return resultMap;
        }
        Map<String, String> timeRangeParam = parseTimeRange(mainFileDTO.getFileDate(), geoRuleVO.getTimeRange());
        String[] mathexpArr = geoRuleVO.getMatchRule().split("\\|");
        List<HtScanningMetadataDTO> ruleFileList = null;
        //标准化处理根据传感器，时间范围，数据等级，查询
        String startTime = timeRangeParam.get("startTime");
        String endTime = timeRangeParam.get("endTime");
        if (preProcess) {
            ruleFileList = htScanningMetadataService.listBySensorAndRangeTimeAndLevelAndBand(mainFileDTO.getSensor(), startTime,
                    endTime, geoRuleVO.getLevel(), mainFileDTO.getBands());
            Set<String> mathexpHashSet = new HashSet<>(Arrays.asList(mathexpArr));
            ruleFileList = ruleFileList.stream().filter(item -> {
                String name = item.getFileName();
                String[] splitName = name.split("_");
                return mathexpHashSet.contains(splitName[splitName.length - 2]);
            }).collect(Collectors.toList());
            if (ruleFileList.size() != mathexpHashSet.size()) {
                logger.info("主文件{}扫描过程中，查询geo文件和rpb文件时输入参数和查询出的数量不一致", mainFileDTO.getFileName());
                return null;
            }
        } else {
            //TODO 专业处理时HTHTGEO扫描规则
//            ruleFileList = htScanningMetadataService.listByProductIidAndBandsAndDataLevelAndLonAndLatAndTimeRange(mathexpArr[0],mainFileDTO.getBands(),
//                    geoRuleVO.getLevel(),mainFileDTO.getLon(),mainFileDTO.getLat(),startTime,endTime);
        }
        if (ruleFileList.isEmpty()) {
            logger.info("未查询到任何geo或rgb文件");
            return null;
        }
        for (HtScanningMetadataDTO fileDTO : ruleFileList) {
            String currentFilePath = geoPathPrefix + File.separator + fileDTO.getFilePath();
            File file = new File(currentFilePath);
            if (!file.exists()) {
                logger.info("{}在磁盘上不存在", fileDTO.getFileName());
                return null;
            }
            if ("HDF".equals(fileDTO.getFileType())) {
                geoPathSb.append(",").append(currentFilePath);
            } else if ("RPB".equals(fileDTO.getFileType())) {
                rpbPathSb.append(",").append(currentFilePath);
            }
        }
        String geoPath = geoPathSb.toString();
        String rpbPath = rpbPathSb.toString();
        if (StringUtils.isNotBlank(geoPath)) {
            resultMap.put("geo", geoPath.substring(1));
        }
        if (StringUtils.isNotBlank(rpbPath)) {
            resultMap.put("rpb", rpbPath.substring(1));
        }
        return resultMap;
    }

    private String l2Rule(String rule, HtScanningMetadataDTO mainFileDTO, String l2PathPrefix) {
        StringBuilder filePathSb = new StringBuilder();
        if (StringUtils.isBlank(rule)) {
            return filePathSb.toString();
        }
        RuleVO l2RuleVO = JSON.parseObject(rule, RuleVO.class);
        if (NULL.equals(l2RuleVO.getMatchRule()) || NULL.equals(l2RuleVO.getLevel())) {
            return filePathSb.toString();
        }
        Map<String, String> timeRangeParam = parseTimeRange(mainFileDTO.getFileDate(), l2RuleVO.getTimeRange());
        String[] mathexpArr = l2RuleVO.getMatchRule().split("\\|");
        List<HtScanningMetadataDTO> ruleFileList;
        String startTime = timeRangeParam.get("startTime");
        String endTime = timeRangeParam.get("endTime");
        boolean isSingleTimes = false;
        if (startTime.equals(endTime)) {
            isSingleTimes = true;
            startTime = TIME_FORMAT.format(LocalDateTime.parse(mainFileDTO.getFileDate(), TIME_FORMAT).plusMinutes(-1 * DIFF_TIME_MINUTE));
            endTime = TIME_FORMAT.format(LocalDateTime.parse(mainFileDTO.getFileDate(), TIME_FORMAT).plusMinutes(DIFF_TIME_MINUTE));
            List<HtScanningMetadataDTO> dataList = htScanningMetadataService
                    .listByProductIidListAndTimeRangeAndLevel(Arrays.asList(mathexpArr), startTime, endTime, l2RuleVO.getLevel());
            double lon = Double.parseDouble(mainFileDTO.getLon().substring(1));
            double lat = Double.parseDouble(mainFileDTO.getLat().substring(1));
            ruleFileList = dataList.stream().filter(dto -> {
                double dLon = Double.parseDouble(dto.getLon().substring(1));
                double dLat = Double.parseDouble(dto.getLat().substring(1));
                return dLon >= lon - 0.5 && dLon <= lon + 0.5 && dLat >= lat - 0.5 && dLat <= lat + 0.5;
            }).collect(Collectors.toList());
        } else {
            //TODO L2多时次文件查询规则，暂时用不到
            logger.info("多时次查询");
            ruleFileList = new ArrayList<>();
        }
        Map<String, List<HtScanningMetadataDTO>> filterMap = ruleFileList.stream()
                .collect(Collectors.groupingBy(HtScanningMetadataDTO::getProductIid));
        if (filterMap.size() != mathexpArr.length) {
            logger.info("与主文件{}要求的L2级文件数量与L2级规则产品标识数量不一致", mainFileDTO.getFileName());
            return null;
        }
        if (isSingleTimes) {
            List<HtScanningMetadataDTO> tempList = new ArrayList<>();
            long mainFileMilli = LocalDateTime.parse(mainFileDTO.getFileDate(), TIME_FORMAT).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
            filterMap.values().forEach(list -> {
                HtScanningMetadataDTO resultDTO = list.stream().min((a, b) -> {
                    long aMilli = LocalDateTime.parse(a.getFileDate(), TIME_FORMAT).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
                    long bMilli = LocalDateTime.parse(b.getFileDate(), TIME_FORMAT).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
                    return Math.abs(aMilli - mainFileMilli) > Math.abs(bMilli - mainFileMilli) ? 1 : -1;
                }).get();
                tempList.add(resultDTO);
            });
            ruleFileList = tempList;
        }
        for (HtScanningMetadataDTO fileDTO : ruleFileList) {
            String currentPath = l2PathPrefix + File.separator + fileDTO.getFilePath();
            File file = new File(currentPath);
            if (!file.exists()) {
                return null;
            }
            filePathSb.append(",").append(currentPath);
        }
        return filePathSb.substring(1);
    }

    private String nwpRule(String nwpFile, String mainFileDate, String npwPathPrefix) {
        StringBuilder filePathSb = new StringBuilder();
        if (StringUtils.isBlank(nwpFile)) {
            return filePathSb.toString();
        }
        RuleVO nwpRuleVO = JSON.parseObject(nwpFile, RuleVO.class);
        if (NULL.equals(nwpRuleVO.getMatchRule()) || NULL.equals(nwpRuleVO.getLevel())) {
            return filePathSb.toString();
        }
        //将主文件时间转为世界时来匹配数值预报数据
        mainFileDate = TIME_FORMAT.format(LocalDateTime.parse(mainFileDate, TIME_FORMAT).plusHours(-8L));
        //查询48小时内在数据库种条件要素的文件是否存在，并且数量至少为3个。
        Long earlyHour = (-1) * 48L;
        String earlyTime = TIME_FORMAT.format(LocalDateTime.parse(mainFileDate, TIME_FORMAT).plusHours(earlyHour));
        String[] mathexpArr = nwpRuleVO.getMatchRule().split("\\|");
        List<DbDmsScanningMetadataAuxInfoDTO> earlyAllData = dbDmsScanningMetadataAuxInfoService.
                listByFileWantListAndRangeTimeOrder(Arrays.asList(mathexpArr), earlyTime, mainFileDate);
        Map<String, Long> countAllNwpMap = earlyAllData.stream()
                .collect(Collectors.groupingBy(DbDmsScanningMetadataAuxInfoDTO::getFileWant, Collectors.counting()));
        if (mathexpArr.length != countAllNwpMap.size()) {
            logger.info("48小时内满足的要素种类数量不正确");
            return null;
        }
        for (Map.Entry<String, Long> entry : countAllNwpMap.entrySet()) {
            if (entry.getValue() < 3) {
                logger.info("{}--->要素的数量在48小时的范围内小于3", entry.getKey());
            }
        }
        //过滤筛筛选出符合规则要求的时次的要素文件  每种要素3个数据信息
        Map<String, String> timeRangeParam = parseTimeRange(mainFileDate, nwpRuleVO.getTimeRange());
        LocalDateTime nwpStartTime = LocalDateTime.parse(timeRangeParam.get("startTime"), TIME_FORMAT);
        LocalDateTime nwpEndTime = LocalDateTime.parse(timeRangeParam.get("endTime"), TIME_FORMAT);
        //key:要素 value:[nwp数据（时间+时次会重复）]
        Map<String, List<DbDmsScanningMetadataAuxInfoDTO>> filterMap = earlyAllData.stream().filter(dto -> {
            LocalDateTime dtoLocalDateTime = LocalDateTime.parse(dto.getFileDate(), TIME_FORMAT).plusHours(dto.getFileTimeSecond());
            return !nwpStartTime.isAfter(dtoLocalDateTime) && !nwpEndTime.isBefore(dtoLocalDateTime);
        }).collect(Collectors.groupingBy(DbDmsScanningMetadataAuxInfoDTO::getFileWant));
        for (Map.Entry<String, List<DbDmsScanningMetadataAuxInfoDTO>> entry : filterMap.entrySet()) {
            List<DbDmsScanningMetadataAuxInfoDTO> wantList = entry.getValue();
            List<DbDmsScanningMetadataAuxInfoDTO> nwpInfoList = new ArrayList<>();
            Map<String, DbDmsScanningMetadataAuxInfoDTO> hash = new HashMap<>();
            for (DbDmsScanningMetadataAuxInfoDTO nwpDTO : wantList) {
                String formatDate = TIME_FORMAT.format(LocalDateTime.parse(nwpDTO.getFileDate(), TIME_FORMAT).plusHours(nwpDTO.getFileTimeSecond()));
                if (!hash.containsKey(formatDate)) {
                    hash.put(formatDate, nwpDTO);
                    nwpInfoList.add(nwpDTO);
                }
            }
            if (nwpInfoList.size() < 3) {
                logger.info("{}要素在规则的时间范围内个数小于3", entry.getKey());
                return null;
            }
            //查找最接近的三个数量文件
            List<Long> nearPrimaryFileTime = findNearDateNwpFile(nwpInfoList, mainFileDate);
            //判断磁盘上是否存在
            StringBuilder sb = new StringBuilder();
            for (Long keyMilli : nearPrimaryFileTime) {
                String keyTime = TIME_FORMAT.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(keyMilli), ZoneId.systemDefault()));
                DbDmsScanningMetadataAuxInfoDTO currentFileDTO = hash.get(keyTime);
                String currentPath = npwPathPrefix + File.separator + currentFileDTO.getFilePath();
                File file = new File(currentPath);
                if (!file.exists()) {
                    logger.info("{}--->nwp文件在磁盘上不存在", file.getName());
                    return null;
                }
                sb.append(",").append(currentPath);
            }
            filePathSb.append(";").append(sb.substring(1));
        }
        return filePathSb.substring(1);
    }

    private List<Long> findNearDateNwpFile(List<DbDmsScanningMetadataAuxInfoDTO> nwpInfoList, String
            mainFileDate) {
        long primaryFileMilli = LocalDateTime.parse(mainFileDate, TIME_FORMAT).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
        List<Long> nearPrimaryFileTime = new ArrayList<>();
        for (int j = 0; j < nwpInfoList.size(); j++) {
            DbDmsScanningMetadataAuxInfoDTO metadataAuxInfoDTO = nwpInfoList.get(j);
            long currentFileMilli = LocalDateTime.parse(metadataAuxInfoDTO.getFileDate(), TIME_FORMAT)
                    .plusHours(metadataAuxInfoDTO.getFileTimeSecond())
                    .atZone(ZoneId.systemDefault())
                    .toInstant()
                    .toEpochMilli();
            if (j < 3) {
                nearPrimaryFileTime.add(currentFileMilli);
            } else {
                //主文件时次右边是从大到小遍历，所以直接替换，保持最右是最小最近的文件时间，最左边是最大的。
                if (currentFileMilli - primaryFileMilli >= 0) {
                    nearPrimaryFileTime.remove(0);
                    nearPrimaryFileTime.add(currentFileMilli);
                } else {
                    //左边进行比较
                    long dif = primaryFileMilli - currentFileMilli;
                    long max = nearPrimaryFileTime.stream().max((a, b) -> Math.abs(a - primaryFileMilli) > Math.abs(b - primaryFileMilli) ? 1 : -1).get();
                    if (dif < Math.abs(max - primaryFileMilli)) {
                        nearPrimaryFileTime.remove(max);
                        nearPrimaryFileTime.add(currentFileMilli);
                    } else {
                        break;
                    }
                }
            }
        }
        return nearPrimaryFileTime;
    }


    private Map<String, String> parseTimeRange(String mainFileDate, String timeRange) {
        Map<String, String> resultMap = new HashMap<>();
        resultMap.put("startTime", mainFileDate);
        resultMap.put("endTime", mainFileDate);
        if (timeRange.equals("NULL")) {
            return resultMap;
        }
        String[] timeSplit = timeRange.split(",");
        long startPlusMinute = -1 * Math.abs(Long.parseLong(timeSplit[0]));
        long endPlusMinute = Math.abs(Long.parseLong(timeSplit[1]));
        LocalDateTime mainFileLocalDateTime = LocalDateTime.parse(mainFileDate, TIME_FORMAT);
        String startTime = TIME_FORMAT.format(mainFileLocalDateTime.plusMinutes(startPlusMinute));
        String endTime = TIME_FORMAT.format(mainFileLocalDateTime.plusMinutes(endPlusMinute));
        resultMap.put("startTime", startTime);
        resultMap.put("endTime", endTime);
        return resultMap;
    }

    /**
     * 按照天擎规范拼装参数
     *
     * @param inputParams
     * @param ruleParams
     * @param taskDTO
     * @return
     */
    public String assembleTianQingRule
    (Map<String, Object> inputParams, Map<String, Object> ruleParams, HtScheduleJobDTO taskDTO) {
        TianQingParam tianQingParam = new TianQingParam();
        //拼装算法Id
        HtAlgorithmConfigurationDTO algorithmConfigurationDTO = htAlgorithmConfigurationService.findById(taskDTO.getAlgoId());
        String algorithmIdentify = algorithmConfigurationDTO.getAlgorithmIdentify();
        tianQingParam.setAlgorithmIdentify(algorithmIdentify);
        //拼装扫描参数
        if (ruleParams.size() == 1 && ruleParams.containsKey("")) {
            tianQingParam.setRuleParams(null);
        } else {
            logger.info("主参数异常");
        }
        //拼装动态参数
        if (inputParams.size() == 1 && inputParams.containsKey("")) {
            tianQingParam.setInputParams(null);
        } else {
            tianQingParam.setInputParams(inputParams);
        }
        //拼装任务Id
        tianQingParam.setTaskId(taskDTO.getId());
        //拼装开始时间
        Date redoStartDate = taskDTO.getRedoStartTime();
        String redoStartTime = "NULL";
        if (redoStartDate != null) {
            redoStartTime = DateUtils.formatDateTime(redoStartDate, "yyyyMMddHHmmdd");
        }
        tianQingParam.setRedoStartTime(redoStartTime);
        //拼装开始时间
        Date redoEndDate = taskDTO.getRedoStartTime();
        String redoEndTime = "NULL";
        if (redoStartDate != null) {
            redoEndTime = DateUtils.formatDateTime(redoEndDate, "yyyyMMddHHmmdd");
        }
        tianQingParam.setRedoEndTime(redoEndTime);
        //拼装重做recordId
        tianQingParam.setRecordId("NULL");
        String s = JSONObject.toJSONString(tianQingParam);
        return s;
    }


}
